Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forward giving error

 
clyde melly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ForwardServlet extends HttpServlet
{
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String message = "This is a test";
RequestDispatcher rd =req.getRequestDispatcher("login.html");
rd.forward(req, res);
}

}
Requestdispatcher gives problem?kindly help
 
Anand Loganathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* The pathname specified may be relative, although it cannot extend outside the current servlet context.
find out where your html file is existing
* If the path begins with a "/" it is interpreted as relative to the current context root.
give the pathname is ("/*.html") // relative path from servlet root.
* This method returns null if the servlet container cannot return a RequestDispatcher.
Make sure that your file is existing in the specified path.
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please specify what the problem is. Or rather put the stack trace.
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the html file in the same folder .I dont think so..so just specify the path according to the folder.
for ex.
if the servlet file is in classes folder and the html is in html folder.
then write the code as
getServletContext().getRequestDispatcher("../html/filename.html");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic