Solved

How do call a Servlet from a JSP

Posted on 2007-11-20
6
10,323 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
Unable to open debugger port in Intellij idea 6 139
bitbucket vs gitbucket 3 55
Problem to start Neon 20 84
Animated .jpg? 13 57
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now