File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to call a servlet from a jsp

 
krishna Gajarla
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64181
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
krishna Gajarla
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64181
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you ....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic