aspose file tools*
The moose likes JSP and the fly likes how to call a servlet from a jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to call a servlet from a jsp" Watch "how to call a servlet from a jsp" New topic
Author

how to call a servlet from a jsp

krishna Gajarla
Greenhorn

Joined: Oct 02, 2005
Posts: 21
hai,
can any body please provide me the model code to call a servlet from a jsp.

thanks in advance.
[ June 13, 2006: Message edited by: Bear Bibeault ]

Thanks and Regards,<br />krishna<br />------------------<br />Charles Darwin: <br />"It is not the strongest of the species that survives, <br />nor the most intelligent, <br />but the one most responsive to change"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Don't you have that sort of backwards? Usually, a controller servlet forwards to a JSP.

The term "call" has no real meaning here. What are you really trying to do?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
krishna Gajarla
Greenhorn

Joined: Oct 02, 2005
Posts: 21
actually speaking, this was the question i faced in the interview.

here the "call", he(interviewer) referring is to invoke a servlet from a jsp.

Am i clear or not?
because still I'm a learner. If I'm wrong in the question itself please clarify me.

But, this was the question i faced.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Depends what the person asking the question intended.

If the output of the servlet is to be included in the JSP, you could use the JSP include action specifying the URL of the servlet. But I wouldn't use a servlet in this case; a custom action would be more appropriate.

And I suppose you could forward from a JSP to servlet, but you'd have to do so before emitting any output which makes it silly to be in a JSP in the first place. Even so, I wouldn't term that a "call".

Likewise with a redirect.

You could also invoke a servlet with Ajax, but that really has nothing to do with the page being a JSP or not.

So my answer to such a question would have been "Why would you want to do something silly like that?", and then explain why I thought it was a silly thing to do. (Couched in a more professional manner, of course).
[ June 13, 2006: Message edited by: Bear Bibeault ]
krishna Gajarla
Greenhorn

Joined: Oct 02, 2005
Posts: 21
thank you ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call a servlet from a jsp