• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forwading From a Servlet to a JSP

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.. i have a login Servelt loaded at the follwoing address

http://localhost:8080/LoginServet

and a simple jsp page at

http://localhost:8080/SimpleJSP

the webapps folder of my tomcat contains a folder for SimpleJSP and a folder for LoginServlet


i want to do the follosing when the login is succesfull .. i want the servelt to take me to the page SimpleJSP .. and if not take me to another JSP . hopw can i do that
i use the folllowing code

RequestDispatcher dispath=
getServletContext().getRequestDispatchr("/SimpleJSP");

dispatch.forward(request,response);


this will not work as SimpleJSP is npt within the LoginServlet folder.. where do i put the SimpleJSP folder to make the above code work. thnaks.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the webapps folder of my tomcat contains a folder for SimpleJSP and a folder for LoginServlet



From the looks of it you have your webapp structure all wrong...

you should have

webapp(folder):-SimpleJsp.jsp
+-WEB-INF
+-+-classes
+-+-+-<package folder e.g. servlets>
+-+-+-+-LoginServlet.java

this way your code should work just fine.

I would suggest you do some research on Wep app file structures as in the arrangements.

[ September 04, 2005: Message edited by: Ola Daniel ]
[ September 07, 2005: Message edited by: Ola Daniel ]
 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for u'r suggestion. its working fine. what do u mean my webapps deirectory is not in right. the tomcat 5.5 server is lo0ading the servlets and jsp fine. by the way is the WEB_INF and xml files not requires for a jsp
, like there required for servlets. thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each directory under webapps is considered by Tomcat to be a separate web application (context).
You can't forward from one context to another.
You will run into more issues down the road (sessions, shipping the app as a war file, etc..) if you don't re-structure it now.
 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic