Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Rajasekhar Eega
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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...


 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!