Here's how you call a servlet from jsp.

<form action="servlet/Myservlet" method="post">
<input type="submit" name="B1" value="Invoke Servlet">
<input type="hidden" name="parameter1" value="something_to_pass_to_servlet">
</form>

You can make the form
action="http://mymachine:8080/jsp_app/servlet/Myservlet" from a regular html
page as well.

To make the servlet give information back to the referring page, called
test_page.jsp,  try this in the servlet code: (incomplete)

...
request.setAttribute("message", "A message from the servlet");
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/test_page.jsp");
rd.forward(request, response);
...

To receive data from a servlet, your jsp page, test_page.jsp, needs code
like this:
...
<%
String message = (String)request.getAttribute("message");
%>
<p><%= message %></p>
...

Have fun...

-cm


-----Original Message-----
From: Ganesh N.M [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 31, 2000 1:15 PM
To: [EMAIL PROTECTED]
Subject: Jsp to Servlet and ViceVersa


Hi All,

Can any one give me sample code for calling servlet from JSP and viceversa?

thanx in Advance.

Bye,

Ganesh

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to