File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with encodeURL
 
Similar Threads
NullPointerException on getServletContext
comparing strings with equals method
How to store and retrieve images to MS access and MYsql database
RequestDispatcher.forward problem
java.sql.SQLException: No suitable driver in DB2 7.01