permaculture playing cards
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 Building Microservices this week in the Design 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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Problems with encodeURL
jQuery in Action, 3rd edition