• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP redirection problem

 
Pradeeep Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am using a JSP login page through which i reach to the home page after successfull login. but on home page when i click on any submit button i got back again on the login page . Even i am not using any session tacking. Here
is my code please tell me if any problem in it.
<%@ page language="java"
import="java.util.*,java.sql.*,com.gipl.JSPLib.*"
pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%
String fname, lname, user, country;
JSPFormatFunctions jsfff = new JSPFormatFunctions("local");
JSPSiteFunctions jssf = new JSPSiteFunctions("local");
JSPValidations jsv = new JSPValidations("local");
int count = 0;

Statement stmt = null;
ResultSet rst = null;
%>
<%

Connection con = jssf.connMain;
fname = request.getParameter("fname");
lname = request.getParameter("lname");
user = request.getParameter("uname");
out.println("Welcome " + fname +" "+ lname);

%>
<html>
<head>
<title>Admin Home Page</title>
<link rel="stylesheet" type="text/css"
href="/FirstAssignment/css/styles.css">
</head>
<body>
<form method="post">
<table>
<tr>
<td>
<input type="text" name="country">
</td>
<td>
<input type="submit" value="Add Country" >
</td>
</tr>
</table>
</form>


<%
if (request.getMethod().equalsIgnoreCase("POST")) {

country = request.getParameter("country");
out.println(country);

}
%>



</body>

</html>
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use code tags to post your code.

Its is bot a good idea to use scriplets. You can make use of MVC design pattern which will prove very helpful in maintaining your code.
Are you using basePath to direct your page to some location?
[ December 18, 2008: Message edited by: Himanshu Gupta ]
 
Pradeeep Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to you when i put the name of same page in action attribute of <form tage > page reamins on the same but don't accept the parameters forwarded from previous page.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to keep in mind that all request parameters are in request scope. When you are hitting submit button then a new request is going to the server and it knows nothing about the previous request. To solve this you can put the parameters in the session. It will be better if you rework your code following MVC pattern. It will not only give you easy to maintainable code but also help you on debugging your application more easily.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!