Solved

How do call a Servlet from a JSP

Posted on 2007-11-20
6
10,333 Views
Last Modified: 2013-11-24
How do I call a servlet from a JSP
0
Comment
Question by:shoganfl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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)
Suggested Courses

623 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