Solved

How do call a Servlet from a JSP

Posted on 2007-11-20
6
10,327 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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 101
Where do I learn ES6? 3 78
How can I   ajax html table  rows? 20 78
tomcat administrtor 12 61
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)

821 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