This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Problems with encodeURL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problems with encodeURL" Watch "Problems with encodeURL" New topic
Author

Problems with encodeURL

Hui Ge
Greenhorn

Joined: Mar 11, 2005
Posts: 25
My doPost method:

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
String userid = req.getParameter("userid");
String password = req.getParameter("password");


if (userid != null && password != null && userid.length() > 0 && password.length() > 0) {

ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();
//context param
String driverClassName = context.getInitParameter("driverClassName");
String dbUsername = context.getInitParameter("dbUsername");
String dbPassword = context.getInitParameter("dbPassword");
//config param
String dburl = config.getInitParameter("dburl");

MySqlDAO dao = new MySqlDAO();
try {
dao.init(driverClassName, dburl, dbUsername, dbPassword);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
throw new ServletException("ClassNotFoundException", e1);
} catch (SQLException e1) {
e1.printStackTrace();
throw new ServletException("SQLException", new SQLException());
}
try {
UserObject userObj = dao.verifyUser(userid, password);
if( userObj != null) {
HttpSession session = req.getSession();
session.setAttribute("userObj", userObj);
ServletContext ct = getServletContext();
String url = res.encodeURL("/jsp/welcome.jsp");
RequestDispatcher rd = ct.getRequestDispatcher(url);
rd.forward(req, res);
} else {
res.setStatus(HttpServletResponse.SC_FORBIDDEN);}
} catch (SQLException e) {
e.printStackTrace();
throw new ServletException("SQLException", e);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


} else {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
}
return;
}

Sorry about the formatting. I would expect the url String to consist of the JSESSIONID but it didn't. Anyone knows why?
Vijay Kiran
Greenhorn

Joined: Nov 18, 2004
Posts: 21
If your browser accepts cookies the URL will never contain the JSESSIONID parameter.


Vijay<br />I blog, therefore I am<br /><a href="http://www.vijaykiran.com" target="_blank" rel="nofollow">www.VijayKiran.com</a>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problems with encodeURL