How to Include a servlet in a jsp

Hello,
My jsp pages are all tied to respective Servlets. So when I have to forward to a jsp, I forward to a servelt which redirects to that jsp.
Now I have a jsp page which has to include another jsp page.
So I am trying to include a servlet in my jsp page which inturn redirects itself to the included jsp.
Have tried doing the following
<jsp:include page="../../servlet/ServletName" flush="true">
</jsp:include>
does not work. It compiles well but no output
any ideas ????
~ Soumya

It does not seem to work... Let me give you the snippet of code I used.
calendarEntry.java - the parent jsp
<tr rowspan="60%">
<td width="100%">
     <jsp:include page="file://c:/../../servlet/MonthEventList">
     </jsp:include>
</td>
</tr>
MonthEventList.java - the included servlet
import javax.servlet.*;
import javax.servlet.http.*;
public class MonthEventList extends HttpServlet {
     * Attributes
     private static final String CONTENT_TYPE = "text/html";
     private HttpSession session;
     public void init() throws ServletException
     public void doPost(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException
          try {     
          HttpSession session = request.getSession(true);
          String url;
     url = "/jsp/site/calendar/monthEventList.jsp";
                    //ReDirect to where the page is going
                    response.sendRedirect(url);
                    return;
          } catch (Exception ex) {
          String url="/jsp/site/calendar/main/servletError.jsp;
     response.sendRedirect(url);
          return;
     public void doGet(HttpServletRequest request,HttpServletResponse
response) throws ServletException, IOException
          doPost(request, response);
monthEventList.jsp
just displays some dummy data
So if this is the case, do you think the <jsp:include> can work ??
Thanks in advance
Soumya

Similar Messages

  • How to include a servlet in JSP ?

    Hi,
    Would you please to teach me how I can include a servlet class in JSP ?
    Would you please to teach me and give me a simple example ?
    My purpose is that I want to use Template model, but I want to show an Image file(that is in the dabase) in JSP.
    I use that servlet to read an image in database and show it in the web using JSP.
    Please teach me.
    Best regards,
    Eric

    Hiya,
    What you're doing is pretty simple and doesn't even require JSP. Just source the SRC tag of <IMAGE> to the servlet, like this:
    <IMG SRC="/servlet" WIDTH="x" HEIGHT="y">
    And you're done.
    Of course, the servlet has to first set the correct response type and return the image for this to work.
    Hope this helps,
    -ike, .si

  • Include a Servlet into a JSP page

    Hi guys,
    When i try to include a Servlet into my JSP, the execution of the JSP stops...Somebody know why???

    Hi guys,
    When i try to include a Servlet into my JSP,the
    execution of the JSP stops...Somebody knowwhy???
    No, and do you know why ? Bcos including a
    servlet
    in
    a jsp doesnt stop the execution of the jsp. Sotell
    us that you tried to do, post some relevant
    code,
    for us to help you.
    ram.<%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page buffer="500kb"%>
    <html>
    <head><title>JSP Page</title></head>
    <body>
    <jsp:include page="/showCryptValue"
    ptValue" flush="true" />
    asdfasdfasdfasdfasdf
    </body>
    </html>
    that's the source code....do you have any idea????
    Thak's a lottttFrom linxpda:
    1) setting the flush="false" parameter for thejsp:include tag?
    Here is the problem that I, and perhaps linxpda,
    think you have:
    You get an exception in the servlet.
    You have already written to and flushed the response,
    therefore you can not see the exception on your
    screen (seeing the exception on screen requires a
    send redirect to the error page, which can't happend
    when the response is already committed).
    The exception that is occuring MAY be alreay written
    in your logs, take a look.
    To see the problem on screen so as to be able to
    identify it, make sure your include tag DOES NOT
    flush the buffer. That means change
    <jsp:include page="/showCryptValue" flush="true" />
    to
    <jsp:include page="/showCryptValue" flush="false" />Hi!
    No even setting flush false or true it works...If somebody have done this before tell me how have you did....If you can post your code!
    []'s
    Falow

  • How to include an ASP page from JSP?

    I had a working ASP page to be repeated on each page of the web site as an navigation bar updated from a single SiteMap.xml. Anyone knew how to include the ASP page from the JSP app?
    Thanks

    You might achieve your desired result by calling the ASP page from your JSP controller (server side) using the standard JAVA HTTP classes you could then process the resulting XML. I suggest you look at the JAVA API for more information in particular the JAVA.NET package and the HTTPUrlConnection class...
    http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html
    Hope this helps,
    BRgds,
    Simon

  • Can I include a servlet in a jsp page?

    Is there anyway to include a Servlet in JSP page?

    What exactly do you want to achieve? And are you using 'include' in the generic sense or in the [JEE sense|http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html#include(javax.servlet.ServletRequest,%20javax.servlet.ServletResponse)]?
    By the way, behind the scenes, a JSP gets compiled into a servlet.
    Edited by: nogoodatcoding on May 18, 2009 9:50 AM

  • How include a Servlet into a JSP page?

    Hi!!
    I need make a combobox with a servlet and place its result into a jsp page.
    The servlet is in a package, but when i do: <jsp:include file="sic.view.servlet.ComboServlet" />
    tell me that "file attribute isn�t a valid attribute name"
    whow can i do to make the combobox whit the servlet and include this into the jsp page??
    Thanks!!
    PD: Sorry my pour English...

    Servlets should be mapped to a URL, then you access the servlet via that URL.
    The servlet mapping is done in the web.xml (in WEB-INF/ directory of your web application)
      <servlet>
        <servlet-name>
          Combo_S
        </servlet-name>
        <servlet-class>
          sic.view.servlet.ComboServlet
        </servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>
          Combo_S
        </servlet-name>
        <url-pattern>
          /combo
        </url-pattern>
      </servlet-mapping>Then you would use:
    <jsp:include file="combo" />
    to include it.
    Make sure the class file gets put in the right package under WEB-INF/classes/

  • How to include a html file in jsp

    hi all
    I have a question about including a html in jsp.
    here's the sample of my jsp file:
    <%
    String filename = "helloworld.html";
    %>
    <%@ include file="helloworld.html" %>
    how will you go about doing it so that the included file depends on the variable "filename"? I've tried doing the following but I got an error:
    <%@ include file=filename %>
    Thank you very much :)

    try this:-
    <%
    String filename = "helloworld.html";
    %>
    <jsp:include page='<%= filename %>' />
    This should work.

  • How to include a .js file into .jsp file.[.js file resides in a package]

    Hi,
    How do i include an external .js(JavaScript) file into a JSP file?My .js file is located in some package(lets say abc.jar). Below is my application structure:-
      jsp
       |
       ->MyJsp.jsp
      lib
       |
       |
    abc.jar
        |
        |
        ->com.abc.test
                     |
                     |
                     ->Test.java
                     ->abc.jsHow do i include "abc.js" file in "MyJsp.jsp" file?
    Please help.
    Thanks,
    Kiran
    Edited by: Adimulam on Jun 2, 2008 1:22 PM

    Even this is also not possible because, the code in that package is developed by DWR and i am just adding it to my lib folder and importing the respective classes. In the same manner i need to include the *.js* file in the JSP.It took me about 3 minutes reading through the [DWR Getting Started|http://getahead.org/dwr/getstarted] page to learn that you don't have to do any of that. Perhaps you should read that page?

  • How to include the javafx program in JSP page

    I am working on a college project and i have got a problem that how will I can use the javafx program in JSP.
    plz imform me as soon as possible

    The JavaFX app can be included in JSP as an Applet.

  • How to create a Servlet Exception in jsp

    Greetings,
    I would like to know if someone knows how create a servlet exception in a JSP.
    Thx

    What for? new ServletException() - IIRC it's not abstract.

  • Hi, i've a question, how to comunicate from servlet to a JSP and viceversa?

    i would like to know how to do this and if its possible an example i'll appretiate it much. thanks

    You have a mechanism called "forwarding", with which you can pass control from one resource (servlet/jsp) to another resource (servlet/jsp). You do this using a RequestDispatcher, which you can get from the HttpServletRequest object. If for example you want to forward to "index.jsp" which is in the root of your web application, you would do this in your servlet:
    RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
    rd.forward(request, response);
    return;(watch the return statement, you must manually return after a forward, or else the servlet will continue executing!). A forward will NOT create a new request, the same request is passed to the new resource (to create a new request, use a redirect in stead, also done with the RequestDispatcher).
    To pass objects between the two resources when doing a forward, use request.setAttribute(), request.getAttribute() and jsp:useBean.

  • How to include external js file in jsp page??

    Hiii...i am new bie in jdeveloper....
    and trying to add external js file to a jsp page...
    the adress of javascript file is [ Web Content/WEB-INF/jsp/script/test.js ]
    adress of jsp page is [ Web Content/WEB-INF/jsp/WelcomePage.jsp ]
    so what source address of js file i have to give in jsp page.....

    Hi,
    In order for the jsp page to get the js file, it has to be accessible via an http request, and files in WEB-INF aren't. You'll have to put the js file in a different location or provide another way to get the file, such as via a servlet request.
    This is the way to do it. I don't see a use case in that adding a JS file to WEB-IF provids any benefit as the sources could be looked up from the browser anyway. So if your intention is to secure the JS sources, this wont work.
    Frank

  • Servlet not found (jsp include)

    Trying to include a servlet from a jsp. Put the servlet under the default_web_app\web-inf\classes\<package dir structure>\<servlet class name>, and included it with "<jsp:include page="servlet.package.hierarchy.ServletName" flush="true"/>
    That I could think of. OC4J is serving jsps fine through Apache, but OC4J can't find the servlet. Ideas?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Robert Cote ([email protected]):
    Added "/servlet/" to the start of the include name -- that fixed it. Now, however, I can't seem to get oc4j to find my beans (located in the same hierarchy). Using <jsp:usebean...> syntax, the usebean statment seems to get processed, but accessing the bean through it's id yields:
    Syntax error in source
    /mapsis/contacts4_mockup.jsp.java:30: Undefined variable or class name: <bean id>
    I'll try messing w/ the syntax, but thanks in advance for any ideas.<HR></BLOCKQUOTE>
    Is your bean part of a package ?
    Here is an example
    <%@ page import="java.sql.* , oracle.jsp.dbutil.*" %>
    <jsp:useBean id="cbean" class="oracle.jsp.dbutil.ConnBean" scope="session">
    <jsp:setProperty name="cbean" property="User" value="scott"/>
    <jsp:setProperty name="cbean" property="Password" value="tiger"/>
    <jsp:setProperty name="cbean" property="URL" value="jdbc:oracle:thin:@dlsun:1521:P817"/>
    <jsp:setProperty name="cbean" property="PreFetch" value="5"/>
    <jsp:setProperty name="cbean" property="StmtCacheSize" value="2"/>
    </jsp:useBean>
    Hope this helps.. sorry for the delay in replying..

  • How to include servlet in JSP using Include Directive?

    Hi experts,
    am a beginner to JSP.. I want to know,
    is it possible to include a servlet in jsp using include directive? could any one explain me...

    No it is not possible.
    Include directive is like copying and pasting some text into a JSP file, and then translating/compiling it.
    So the only thing you can include with the <%@ include %> directive is a jsp fragment
    It is a static translation/compile time include and thus will always be the same
    By contrast <jsp:include> is a runtime include, and includes the result of running the imported url.
    That URL has to be a complete/standalone jsp/servlet/whatever. However as it is runtime, it can take parameters where the include directive can not.
    Does that answer your homework question?
    Cheers,
    evnafets

  • How to include a jsp page in another jsp jsp page

    hi,
    i m trying to include a jsp page name "header.jsp" into one jsp page name"selectattribute.jsp" i m using these commands in "selectattribute.jsp"
    <%@include file "header.jsp"%> bcz both these jsp page are C:\program files\tomcat 4.0\webapps\examples\jsp\Poject\
    but the problem is that , i m invoking this jsp page "selectattribute.jsp" from a servlet reportcontroller.java using REQUEST DISPATCHER.
    the servlet is in
    C:\Program files\tomcat 4.0\webapps\examples\WEB-INF\classes\Project\
    i want to know how to include some other jsp page in a jsp page and how to invoke applet from jsp page when that particular jsp page is being invoked by servlet.
    plz help
    manish

    use this for including in your selectattribute.jsp
    <jsp:include page="header.jsp" flush="true"/>
    I never tried calling an applet. I think you can write the code for calling the applet in a javabean method and call the method in the jsp

Maybe you are looking for