File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error using forward method

 
clyde melly
Ranch Hand
Posts: 152
  • 0
  • 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 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.
 
Amit KumarS
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
clyde melly
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,I will do the needful and get back to u.Thanx
 
clyde melly
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit still an error page displayed.I'm using jsdk2.0 with the servletrunner utility.No problem with that na.Kindly help.
 
Malli Raman
Ranch Hand
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does jsdk2.0 not support the given forward method in the given code??Will i have to upgrade??
 
praveenkumar singamsetty
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code will work with jsdk2.0 or not??
 
praveenkumar singamsetty
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

RequestDispatcher rd = context.getRequestDispathcer();
<------------------------>
Regards,
M.S.Raman
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does jsdk2.0 not support the given forward method in the given code??Will i have to upgrade??

I cannot express how strongly I recommend that you upgrade.

Tomcat 4.1.29 is the latest stable release of the implementation of a servlet container that replaced (a LONG time ago) the jsdk2.0

Find it at: http://jakarta.apache.org/tomcat


Also... you should not have jsdk2.0 and servlet.jar *both* in the classpath, that is probably confusing the issue.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic