File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to know which servlet/jsp calling a particular servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to know which servlet/jsp calling a particular servlet " Watch "how to know which servlet/jsp calling a particular servlet " New topic
Author

how to know which servlet/jsp calling a particular servlet

Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

hello,

let me explain what i want to know.....
i am using a website where from the Administrator's page the Administrator can see the employee details(showEmployeeDetails.jsp) and also can update employee details(updEmployeeDetails.jsp).

the updation is done through updEmployeeDetails.java servlet, now if i want to call updEmployeeDetails.java from both showEmployeeDetails.jsp) and updEmployeeDetails.jsp, then is it possible??
is there any way to know which page is calling the servlet??

note::
while seeing details, if the Administrator feels like updating or changing some data, she dont have to go back to the update.jsp page, and then from there calling updEmployeeDetails.jsp to finally update the detail calling updEmployeeDetails.java.
i want to minimize this hazzle.


With regards,
rituparna
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

...the updation is done through updEmployeeDetails.java servlet, now if i want to call updEmployeeDetails.java from both showEmployeeDetails.jsp) and updEmployeeDetails.jsp, then is it possible?? is there any way to know which page is calling the servlet??

Servlets are called from the URL patterns defined in web.xml. So if you want the same servlet to be called you should send the request to the correct servlet(using the URL pattern defined) with proper request parameters required to process the request.

Note: If you have done some code that we can see it would be easier to suggest what exactly (and how) should be done...

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

well, ok,
here is the code for updEmployeeDetails.jsp

which is calling the following file....

this file is again calling the following servlet...

now, what i am saying is that is it possible to call this servlet from the page where i am checking the employee details?
my web.xml file is this.....


Sooooo many of codes...............................
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

First of all you should avoid writing Java code inside JSPs (at least in new code). And both doGet() and doPost seems to be used to update the table which is not a good idea. Generally HTTP GET request is considered idempotent (i.e.: safe to execute multiple times without any side effects).

In to your code:
According to this code when the first JSP calls the second it needs a form submit in order to display the data which does not happen automatically. So you'll have to change the design accordingly. Use JSPs only as a view component. This way you can avoid most of the confusion in the code. And call your servlet which handles the retrieval of customer data when user submit a query parameter. Then you may display them in a different JSP by forwarding the request from the servlet.

You may read about MVC pattern to get a better idea how this happens...
Also read about the Request Dispatcher on how to dispatch requests....
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

yeah i know that, but still it was a mistake. actually i wanted to display the values on to textboxes directly from the database table, so i coded in the jsp page.
but ok, now i will store the values fetched, into session/context and then display it into the view.
thanks for reminding me.
i will keep it in mind everytime i code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to know which servlet/jsp calling a particular servlet