#1
  1. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Location
    Brisbane, Australia
    Posts
    1,442
    Rep Power
    29

    Problem Accessing Request Parameter


    I'm trying to display an alert based on a request parameter and it is giving me problems.

    I'm calling the page as follows

    Code:
    // check for duplicate Layer name or title
    	ResultSet rs = DatabaseConnection.Query("SELECT * FROM tblLayers WHERE Layer_Name = '" + request.getParameter("Layer_Name") + "'");
    	if (rs.next())
    	{
    		//duplicate name exists
    		%>
    			<script language="JavaScript">
    				alert("A Layer with this name already exists");
    			</script>
    		<%
    		response.sendRedirect("new_data_registration.jsp?Duplicate=name");
    	}
    	else
    	{
    		rs = DatabaseConnection.Query("SELECT * FROM tblLayers WHERE Layer_Description = '" + request.getParameter("Layer_Description") + "'");
    		if (rs.next())
    		{
    			//duplicate description exists
    			response.sendRedirect("new_data_registration.jsp?Duplicate=title");
    		}
    	}
    	rs.close();
    This appears to work fine and if the redirect happens I see either
    new_data_registration.jsp?Duplicate=name or new_data_registration.jsp?Duplicate=title as the url at the top of the page.

    My problem comes when I try to access the Duplicate paramater. I have attempted to get it using

    Code:
    	<%
    		if (request.getParameter("Duplicate") != null)
    		{
    			%>
    				<script language="JavaScript">
    					alert("A Layer with this " + <%= request.getParameter("Duplicate") %> + " already exists");
    				</script>
    			<%
    		}
    	%>
    For some reason this displays an alert say "A Layer with this menu already exists" when duplicate = name (Note the msg says menu, not name)
    and displays nothing at all when Duplicate = title

    Has anyone got any ideas as to what is going on?
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    OK, this problem likely stems from the redirects. Look at what you are sending to the browser. First you send an alert
    Code:
    <script language="JavaScript">
    	alert("A Layer with this name already exists");
    </script>
    The you send a redirect header
    Code:
    response.sendRedirect("new_data_registration.jsp?Duplicate=name");
    So, when you get to the new_data_registration_page the browser is displaying the alert it got right before the redirect header. Remove that alert and see what it does. Secondly, if all you have is an alert in script tags, and they are not in html tags, that technically is not proper html and some browsers won't display the alert on the second page. Why it would show the first and not the second I don't know, but since it is not "kosher", you should eliminate it as a possible problem. Try looking at the source of the page and see if it is there, or better yet, simply print it out to the screen instead of trying to do an alert.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Location
    Brisbane, Australia
    Posts
    1,442
    Rep Power
    29
    Thanks nemi, the alert in the redirecting page was unneccessary. I just forgot to pull it out. Looking at the source of the generated page sorted me out quickly though.

    The generated code looked like
    Code:
    <script language="JavaScript">
    					alert("A Layer with this " + name + " already exists");
    				</script>
    Obviously wrong. I'm now generating the right code with
    Code:
    <script language="JavaScript">
    					alert("A Layer with this " + <%= "\"" + request.getParameter("Duplicate") + "\""%> + " already exists");
    				</script>
    Thanks for your help.

IMN logo majestic logo threadwatch logo seochat tools logo