• 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

Want to forward a request from JSP to Servlet on href click

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 servlets and one jsp in my application in the following order.

1. MyServlet1---> Here I am catching all my business operation results and forwarding to the jsp for display purpose
2. MyJsp----> Here I am displaying the result with some css styles... Now I need to forward the request to another servlet(which is my second servlet) on href click...

Sample code snippet for your understanding

MyServlet1.java

MyJsp.jsp




MyServlet2.java




Please help on this... Thanks in Advance...


 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not quite sure what you are up to, but here are the next couple steps:

1) Write a second servlet. (It can just print "Hello" for now).
2) Add that servlet to your web.xml (or use an annotation to define the path)
3) Add the link to the JSP based on the path you gave your servlet
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. MyServlet1---> Here I am catching all my business operation results and forwarding to the jsp for display purpose
2. MyJsp----> Here I am displaying the result with some css styles... Now I need to forward the request to another servlet(which is my second servlet) on href click...



There seems to be some confusion here about what happens where in a typical web application.

ALL "href click" operations occur on the client browser and are completely disconnected from the JSP/servlet/whatever that generated the HTML containing the "href" - which has totally forgotten everything about that HTML response except what you the programmer saved in the session.

Whatever the href URL points to is where the client browser will send the request.

Forwarding occurs within your web application, where (presumably) a servlet will get the request and forward to the correct JSP for presentation of the response.

Bill
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:Forwarding occurs within your web application, where (presumably) a servlet will get the request and forward to the correct JSP for presentation of the response.


Good point. I didn't pick up on "forward" in the question. Or rather I didn't interpret it literally.

My post is how to submit a new request to that second servlet on click.
 
Rajasekhar Eega
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply...

Here I am missing the connection between these two servlets where I am using my jsp in between these two. My exact requirement is using the object of first servlet in second servlet.
Is there any option to share data in a web application among different servlets in weblogic server environment.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajasekhar Eega wrote:Here I am missing the connection between these two servlets where I am using my jsp in between these two. My exact requirement is using the object of first servlet in second servlet.
Is there any option to share data in a web application among different servlets in weblogic server environment.


THe servlets aren't directly connected. Instead, you put the data you want to share as an attribute in the HttpSession object. (request.getSession())
 
Rajasekhar Eega
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:
THe servlets aren't directly connected. Instead, you put the data you want to share as an attribute in the HttpSession object. (request.getSession())



Thanks... Now it got resolved and working with session fine...
 
reply
    Bookmark Topic Watch Topic
  • New Topic