Solved

How do call a Servlet from a JSP

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

Accepted Solution

by:
Tomas Helgi Johannsson earned 50 total points
Comment Utility
     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
Comment Utility
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
Comment Utility
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
Comment Utility
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

10 Experts available now in Live!

Get 1:1 Help Now