Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Error using forward method

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,I will do the needful and get back to u.Thanx
 
clyde melly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So does jsdk2.0 not support the given forward method in the given code??Will i have to upgrade??
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code will work with jsdk2.0 or not??
 
praveenkumar singamsetty
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
That new kid is a freak. Show him this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic