dcsimg
Why this command does work ? <br>!_NEWLINE_!RequestDispatcher rd = getServletContext().getRequestDispatcher(forwardURL);!_NEWLINE_! rd.forward(request,response);
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   nor1_leelapattana
Posted On:   Thursday, August 22, 2002 01:30 AM

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { homeURL = null; String forwardURL = ""; String cmd = request.getParameter("cmd"); try { if ("login".equals(cmd)) { forwardURL = "../src/login/login.jsp";//this is correct URL } else if ("doLogin".equals(cmd)) { forwardURL = "../src/login/jsp2.jsp"; // this is correct URL } } catch (Exception e) { } // this below command is work !! request.getRequestDispatcher(forwardURL).forward(request,resp   More>>

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


homeURL = null;

String forwardURL = "";

String cmd = request.getParameter("cmd");

try {

if ("login".equals(cmd)) {

forwardURL = "../src/login/login.jsp";//this is correct URL

} else if ("doLogin".equals(cmd)) {

forwardURL = "../src/login/jsp2.jsp";
// this is correct URL

}




} catch (Exception e) {
}


// this below command is work !!


request.getRequestDispatcher(forwardURL).forward(request,response);


// but when i use this below command doesn't work

//RequestDispatcher rd = getServletContext().getRequestDispatcher(forwardURL);

//rd.forward(request,response);


}

   <<Less

Re: Why this command does work ? <br>!_NEWLINE_!RequestDispatcher rd = getServletContext().getRequestDispatcher(forwardURL);!_NEWLINE_! rd.forward(request,response);

Posted By:   michael_dean  
Posted On:   Thursday, August 22, 2002 09:33 PM

The getRequestDispatcher(String) method in ServletContext requires that the String argument be a path that is relative to the servlet context root (i.e. it must start with "/").



The getRequestDispatcher(String) method in ServletRequest (and inherited by HttpServletRequest) allows paths relative to the current request URL.



Change the assignment for forwardURL to something like:




//this URL will work with either getRequestDispatcher(...) method
forwardURL = "/path/from/servlet/context/root/src/login/login.jsp";
About | Sitemap | Contact