Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JSP variable problem

  • 22-03-2005 12:06AM
    #1
    Moderators, Society & Culture Moderators, Sports Moderators, Paid Member Posts: 12,403 Mod ✭✭✭✭


    Hey,

    have this jsp that prints out an image from a database, with a comment box.
    trying to setit so it only prints the box if the logged in user isn't the user who's image it is.
    The variable being set by the login is working fine, but the variable userName being taken from the DB wont change, which is odd as i have a couple of other strings being initialised in the same way that change for every user.
    I cant figure out why this String remains as the first user who's picture is viewed.
    Any help would be appretiated.

    Here's the code.
    <%@ page import="java.sql.*" %>
    <%
    String url = "jdbc:mysql://localhost/Project";
    Connection connect = null;
    Statement stmt = null;
    ResultSet rs = null;
    String userName = null;
    HttpSession Session = request.getSession(true);
    %><html><body>
    
    <%
    
    	String img = request.getParameter("id");
    	String User = "";
    	Class.forName("com.mysql.jdbc.Driver").newInstance();
    	connect = DriverManager.getConnection(url, "Viewer", "view1");
    	stmt = connect.createStatement();
    	String query = "select UserName,Title, email from images where ImageUrl = '"+img+"' ";
        String title="";
        String email=""; 	
       	rs = stmt.executeQuery(query);
       	while(rs.next())
       	{
    		userName =rs.getString("UserName");
       		title = rs.getString("Title");
       		email = rs.getString("email");
       	}
       	
       	connect.close();
       	rs.close();
    
       	%>
       	<div align = "center">
       	<h1><%=title%></h1>
       	
       	<img src = "<%=img%>"><br>
    	<%    
       	if(Session.getAttribute("Name")!=null)
    	{
    		User = (String)Session.getAttribute("Name");
    	}
    	
    	if(userName.compareTo(User)!=0)
    	{
    	%>	
    	<form action="http://www.performancecars.ie/cgi-bin/form.cgi" method="post" name="Comments">
    	<table>
    	<tr>
    	<td><textarea name="comment"rows="7" cols="32" wrap="soft"></textarea></td>
    	</tr>
    	<tr>
    	<td><div align="center">
                <input name="Sumbit " type="submit" value="Submit Comment">
              </div></td>
    	</tr>
    	</table>
    	<INPUT TYPE="hidden" NAME="form_id" VALUE="ImageLab Commet:-<%=title%>">
        <INPUT TYPE="hidden" NAME="submit_to" VALUE="<%=email%>">
        <INPUT TYPE="hidden" NAME="data_order" VALUE="comment">
    	</form>
    </div>
    <%=userName+" "+User%>
    <%}
    
    %>
       	
       	</body>
       	</html>
    


Advertisement