This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes return to wrong page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "return to wrong page" Watch "return to wrong page" New topic
Author

return to wrong page

jil shi
Greenhorn

Joined: Feb 17, 2004
Posts: 20
i am creating my web site using jsp. the problem that is faced is when i click submit button after execute my page, it will return to wrong page. however i already type return to the relevant page in my program. how to make sure that after click submit button, my page will return to the relevant page. my program is using frame. Firstly, i select option from the list bar. after select, it will execute my program. unfortunately after execute it returned to the wrong page
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Sorry Can't understand your problem. Please post some code.
you specify action in form tag and clicking on submit it goes to the specified action.
<form action="/myjsp.jsp" method="POST">
//form elements here
</form>
jil shi
Greenhorn

Joined: Feb 17, 2004
Posts: 20
<form name="form1" method="post" action="page1.jsp">
<%String propVal = request.getParameter("prop");
out.print(propVal);

if (propVal.equals("klcv")) {
//response.sendRedirect(response.encodeRedirectUrl("klcv_write_online_registration.jsp"));
String server = "localhost";
session.setAttribute("server", server);
String database = propVal;
session.setAttribute("database", database);

Class.forName("org.gjt.mm.mysql.Driver");
DriverManager.registerDriver((Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance());
String url = ("jdbc:mysql://"+server+"/"+database+"" );
Connection conn = (Connection)DriverManager.getConnection(url,"","");

String sql_1 = "SELECT * FROM smbyer INTO OUTFILE 'klcv_smbyer.txt' "+
"FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n' ";
Statement stmt_1 = conn.createStatement();
ResultSet rset_1 = stmt_1.executeQuery(sql_1);
conn.close();

} else if (propVal.equals("sv")) {
//response.sendRedirect(response.encodeRedirectUrl("sv_write_online_registration.jsp"));
String server = "localhost";
session.setAttribute("server", server);
String database = propVal;
session.setAttribute("database", database);

Class.forName("org.gjt.mm.mysql.Driver");
DriverManager.registerDriver((Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance());
String url = ("jdbc:mysql://"+server+"/"+database+"" );
Connection conn = (Connection)DriverManager.getConnection(url,"","");
String sql_1 = "SELECT * FROM smbyer INTO OUTFILE 'sv_smbyer.txt' "+
"FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n' ";
Statement stmt_1 = conn.createStatement();
ResultSet rset_1 = stmt_1.executeQuery(sql_1);
conn.close();

}

String brv= "brv";
session.setAttribute ("database", brv);%>
<h1> </h1>
<h1> </h1>
<META HTTP-EQUIV="refresh" CONTENT="2; URL=page1.jsp">
<h2 align="center"><font color="#000099">Data transfer completed!</font></h2>
</form>
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I'm still not really clear on what you are trying to do...

I don't see a SUBMIT button anywhere in your form...

All the code looks like it does is query a database based on the value of the request parameter named "prop", but nothing is done with the results of the database query.

The session parameter named "database" gets set to either "klcv" or "sv" depending on the value of the "prop" request parameter, but then it is set to "brv" no matter what at the end of the scriptlet.

Your form, if it ever could be submitted, sends a POST request to page1.jsp, however, you also have a META "refresh" on the page that sends a GET request to page1.jsp after 2 seconds.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
jil shi
Greenhorn

Joined: Feb 17, 2004
Posts: 20
The submit button is created at other page. Not the same page with the code that i provided. Below are part coding of submit button page:<form name="form1" method="post" action="select_2_property.jsp" onSubmit="return chk();">
<table border="0">
<tr><td><font color="#0929AF"><strong>Online Registration</strong></font></td></tr>
<tr><td>Select Property That You Are Interested</td></tr>
<tr><td>
<select name="prop">
<option value="done" selected="selected">----- Select -----</option-->
<option value="klcv">Kuala Lumpur Cityview</option>
<option value="sv">Sentul View</option>
</select>    
<input class="submit" type="submit" name="submit" value="Submit">
</td></tr>
</table>
</form>
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Hi jil shi,
I have used the following tag, its working fine at my side.
<META http-equiv="refresh" content="2; URL=/jsp2.jsp">
jil shi
Greenhorn

Joined: Feb 17, 2004
Posts: 20
i knw this code is working fine. when i add list bar to the program, it return to the wrong page. that was the problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return to wrong page
 
Similar Threads
After submit the link parameter get null
returning to the previous page with cleared GUI components
How to busy indicator using jsp page
Question on .submit and reloading form values AFTER the submit button is clicked
facing problem while submitting