Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JSP variable problem

Options
  • 22-03-2005 12:06am
    #1
    Moderators, Society & Culture Moderators, Sports Moderators Posts: 12,272 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