Solved

How do call a Servlet from a JSP

Posted on 2007-11-20
6
10,325 Views
Last Modified: 2013-11-24
How do I call a servlet from a JSP
0
Comment
Question by:shoganfl
6 Comments
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 50 total points
ID: 20320478
     Hi!

Here is an good example : http://www.java2s.com/Code/Java/JSP/ServletForwardJsp.htm
and check also http://www.java2s.com/Code/Java/JSP/Collaboration.htm

Regards,
   Tomas Helig
0
 
LVL 1

Expert Comment

by:r_ran
ID: 20328004
You can use jsp:include, with the address of the servlet.
http://java.sun.com/products/jsp/tags/11/syntaxref1112.html

0
 
LVL 3

Expert Comment

by:ss_p
ID: 20339580
you can call servlet from JSp

1) in the action youc an use the action i.e., name of the servlet

 <Form name="myform" method="Post" action="servletName">

2) if u want to call the servlet from a link

<a href="servletName">click here</a>

3) youc an as well use JSP include or Jsp forwards AS

<jsp:include page="servletName or URL " flush="true" >

or

<jsp:forward page="servletName or URL">

Thank you
SSP
0
 
LVL 2

Expert Comment

by:PallaviJain20
ID: 22476441
Calling a JSP from a Servlet, or vice-versa, can be done using the RequestDispatcher interface, which is part of the Servlet 2.2 specification. Following is the code for sending output to a JSP page from a servlet:

javax.servlet.RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Requested.jsp");
request.setAttribute("Name","Pallavi");
request.setAttribute("Language","Java");
dispatcher.forward(request,response);


The following code shows the method of redirecting the user request to a servlet from a JSP page:

 
<%
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/MyServlet");
        dispatcher.include(request,response);
%>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 134
cookies analysis tools 2 91
Having trouble setting Apache to recognise 2 vitual sites (on different drive). 3 112
null output 3 25
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question