File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problems with encodeURL" Watch "Problems with encodeURL" New topic

Problems with encodeURL

Hui Ge

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) {
throw new ServletException("ClassNotFoundException", e1);
} catch (SQLException e1) {
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 {
} catch (SQLException e) {
throw new ServletException("SQLException", e);
} catch (ServletException e) {
} catch (IOException e) {

} else {

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

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="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Problems with encodeURL
It's not a secret anymore!