• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a servlet from a JSP

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web application where I use JSP's as output I want a JSP to go to a servlet to drive a function. Can you call a servlet from a JSP?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Provide a url to the servlet and click it. Or if you want to dynamically update something on your page you need to use AJAX.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you can.

Three ways do it,

1. By using <jsp:forward> tag

2. If JSP has html <form> element, you can add a attribute called action="<url>" and give URL which match <servlet-mapping> <url-pattern> in web.xml of your application.

3. AJAX call as John said.
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it to work using forward thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic