• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Calling another servlet

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all..........
I have written a program to search and get the details of the employees and display the details.
In the displayed screen i have given two option ,like to Delete or Update.
So to execute the delete or update i have written a deleteServlet and UpdateServlet.

Now my problem is how do i call the deleteServlet or UpdateServlet from my SerachServlet.

I am attaching my code also ...


I also need to know is there any better way to do this application.
I know only a little of jsp.
Instead of using out.println to output the html i know i can use jsp but dont know how to do it.

It will be great if somebody gives me suggestion how to call my deleteServlet and how should i use jsp to make my code appear simple.

Thanks a lot
Ramya.A
[ May 19, 2005: Message edited by: ramya jp ]
 
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
For each value, you can add a link with querystring variables or a small form that points to the update and delete servlets.


I also need to know is there any better way to do this application.
I know only a little of jsp.
Instead of using out.println to output the html i know i can use jsp but dont know how to do it.

It will be great if somebody gives me suggestion how to call my deleteServlet and how should i use jsp to make my code appear simple.



The most popular design pattern for cleaning up server side code and moving all the look and feel code into JSPs is the "Model, View, Controller" (MVC) pattern. There are frameworks out there that implement this pattern for you. Struts is the most well known. Many people (myself included) use this pattern without anyone else's framework.

For a real simple example, go to http://simple.souther.us
and download SimpleMVC.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ramya!

I kindly request you to post any code within the 'code' tags of the UBB

Code, so that your query would be readable. Coming to your question, you

have no where included a 'Delete' or 'Update' button in your SearchServlet.

Probably you might have coded a seperate HTML page for that. So there is no

question of calling the 'updateServlet' or 'deleteServlet' from your

'searchServlet'. One of this should be invoked through the concerned HTML

page. Please clarify if I am wrong. However, RequestDispatcher.forward()

method would do it for you.

cheers,
amar
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry amar for not posting my code properly.
I came to know that i can pass the value to another servlet by using
URLRewritting,cookies,HttpSession.

In my application SearchServlet i want to use URLRewriting method to call my DeleteServlet and UpDateServlet.

I am posting a part of my code where i have done this.



Now my out put screen will applear like this.



So when i click the delete or update link it should take me to the appropriate servlet and do the action written there.

I am able to get the output screen but when i click the delete or Update link i am getting an error saying DeleteServlet not found

So how should i solve this error.

Thanks in advance.
Ramya.A

[ May 20, 2005: Message edited by: ramya jp ]
[ May 20, 2005: Message edited by: ramya jp ]
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have u mapped your servlets to their names in the Web.xml file
there is the class name and the servlet name as well as the url which you can map to call the particular servlet.
The web.xml file will be in the Web-Inf folder.Check it out.
You can give the path where you call the form.
Read up on the web.xml file and you'll have your answer.
What ever form action you give will be mapped to the servlet.
Cheers
Nikhilesh
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nikhilesh...

My doubt is not yet cleared....
I have written an html page where it call a servlet called SearchServlet.
I have dont the web.xml mapping for this.

Here is my web.xml mapping details



Now i was try to call a servlet called DeleteServlet from SearchServlet and was trying to pass value.For this is added the below code in my SearchServlet



And in my DeleteServlet i used



This is what i have done to call from my SearchServlet to DeleteServlet..
I want to know apart from the above web.xml mapping am i need to make anything more to call my DeleteServlet from my SearchServlet.

Please reply in detail.....
Thanks in advance
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you were to pull out your business logic to update and delete to Plain Old Java Objects (POJO), then you wouldn't need to call another Servlet. They could all share the same POJOs to do their work. This is a cleaner design.

Mark
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you have not registered the Delete servlet, u have to to call sendredirect by passing the path of servlet. once you do it by using urlrewriting you can invoke the delete servlet and after performing the task can redirect the request to search page again.

I will suggest you to go for JSp soln instead of servlet.
in case of jsp you have to drop you out.print* with simple text

e.g if you have written a statement like out.print("<Html>");


just write <html>


for any logic where u need java code just write it inside
<%
//........java code
%>

html code

<%
...java code
%>
reply
    Bookmark Topic Watch Topic
  • New Topic