import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ForwardServlet extends HttpServlet { public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { getServletContext().getRequestDispatcher("login.html").forward(req, res); }
} The html file which call's this servlet <html> <body bgcolor="#ccccff"> <form action="http://localhost:8080/servlet/ForwardServlet" method="post"/> <input type="submit" value="OK"/> </body> </html> The init method is called,but an error page is displayed.I'm using jsdk2.0 to test.Plz help I also tried http://localhost:8080/servlet/ForwardServlet,but error page with init being called.
hiiii, i think the problem is with the way u r calling the login.html... it has to be absolute path.. if not then you will have to use the request object to call the getRequestDispatcher() in which you can pass relative path but in that case u will have to call it like
i hope this is clear.. if still in doubt please revert back Thanks Amit
****************************<br />In 24 hrs Earth rotates once on its Axis.
clyde melly
Ranch Hand
Joined: Sep 04, 2003
Posts: 152
posted
0
Hi Amit,I will do the needful and get back to u.Thanx
clyde melly
Ranch Hand
Joined: Sep 04, 2003
Posts: 152
posted
0
Amit still an error page displayed.I'm using jsdk2.0 with the servletrunner utility.No problem with that na.Kindly help.
Originally posted by clyde melly: Amit still an error page displayed.I'm using jsdk2.0 with the servletrunner utility.No problem with that na.Kindly help.
Hi Clyde Melly, Following code is working in weblogic server 7.1. As Amit said you missed '/' path in the login.html file. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ForwardServlet extends HttpServlet { public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { getServletContext().getRequestDispatcher("/login.html").forward(req,res);
} } Regards, M.S.Raman
clyde melly
Ranch Hand
Joined: Sep 04, 2003
Posts: 152
posted
0
So does jsdk2.0 not support the given forward method in the given code??Will i have to upgrade??
Hi... U should take care of the context root also.. r both the servlets in the same context root if they exist then u can use simple name else u should specify the rootname n simplename
clyde melly
Ranch Hand
Joined: Sep 04, 2003
Posts: 152
posted
0
The code will work with jsdk2.0 or not??
praveenkumar singamsetty
Greenhorn
Joined: Oct 29, 2003
Posts: 6
posted
0
getServletContext().getRequestDispatcher("login.html").forward(req, res); The code will certainly work... but make sure of the context root in getRequestDispatcher specify it as("UrOwnContextRoot/login.html"); try it out... it worked 4 me...
clyde melly
Ranch Hand
Joined: Sep 04, 2003
Posts: 152
posted
0
Not get an error that the requestdispatcher stuff is not found within the servletcontext interface.I set the classpath again by putting jsdk.jar and servlet.jar in my existing classpath.Again just to confirm jsdk2.0 supports this feature??
Malli Raman
Ranch Hand
Joined: Nov 07, 2001
Posts: 312
posted
0
Originally posted by clyde melly: Not get an error that the requestdispatcher stuff is not found within the servletcontext interface.I set the classpath again by putting jsdk.jar and servlet.jar in my existing classpath.Again just to confirm jsdk2.0 supports this feature??
Hi Clyde, Just try to print the RequestDispatcher object (I think you are getting null for this one). Else you can try this option <-------------------------------> ServletContext context = null; public void init(ServletConfig config) throws ServletException { super.init(config); context = config.getServletContext(); } inside your doGet method initialize the RD as