Servlet include

see my code now:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Switch extends HttpServlet{
public void service(HttpServletRequest req,
HttpServletResponse resp)
throws IOException,
ServletException{
resp.setContentType("text/html");
PrintWriter out=new PrintWriter(resp.getOutputStream());
out.print("<html>");
out.print("<body>");
out.print("byebye!");
RequestDispatcher rd=getServletContext().getRequestDispatcher ("/ee.jsp");
rd.include(req,resp);
out.print("</body>");
out.print("</html>");
out.close();
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//ee.jsp
<%
out.print(session.getAttribute("name"));
%>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
i put the two files under the correct directory of tomcat4.0,when i call the servlet in my browser(ie5),it throw a exception:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
why?i wonder how can i dynamically include a jsp file in my servlet?
help me
thanks

The included JSP needs to use the same PrintWriter that has already been used.
The simplest way to fix this in Switch should be to replace
PrintWriter out=new PrintWriter(resp.getOutputStream());
with
PrintWriter out = resp.getWriter();
Good luck!

Similar Messages

  • Can't parse javax.servlet.include.query_string using HttpUtils replacement

    The javadoc for HttpUtils.parseQueryString() says that it has been deprecated and "moved" to HttpServletRequest, but it looks to me like it has not.
    Specifically, if I call request.getAttribute("javax.servlet.include.query_string") on an included servlet to get its query string, I can't parse it.
    Looks like I either have to write my own parser, or use the deprecated method of HttpUtils. Why do I have to make this crappy choice? Why is HttpUtils deprecated, instead of fixed? Or is there another way?

    again with the assuming that one has the request object.
    Nope, got a string, that's it.
    back to original post.

  • Servlet Include don't work on tomcat 4

    Hello all!
    I use the ServletInclude tag in uix to include a jsp-snippet or a servlet. It works in my local deployment, but not on the Tomcat 4 Server. No content of the jsp/Servlet is shown and the other part of the uix after the include tag aborts.
    Has anyone the same behaviour on the tomcat too?
    What is the solution?
    Thanks Roger

    Hello,
    doesn't anybody work with the Tomcat?

  • The servlet include a send mail function,and can not retrun immediately!

    In the post/get funtion ,a send mail function is present,and this will make the client wait a long time to continue to browse,how to let it return as soon as possible?

    Not sure I understand your question, but I think you want to know how to handle a lengthly operation (send mail in your case) without making the client wait a long time for a response. If that is the question, you can kick off a new thread to handle the mail sending while replying to the browser client immediately. There's a good intro to threads and examples in the Jave tutorial (http://java.sun.com/docs/books/tutorial/essential/threads/index.html)

  • Please explain servlet spec portion

    Hi all,
    In section SRV 8.3(Include method) of Servlet specification v2.3 it is said that
    "It can only write information to the ServletOutputStream or Writer of the response object and commit a response by writing content past the end of the response buffer, or by explicitly calling the flushBuffer method of the ServletResponse interface."
    Does this mean that an included servlet must explicitly call flushBuffer method or its output must exceed the buffer size to send the output to client ?.
    Does the end of the service method automatically flushes the output ?

    The full quote:
    The target servlet of the include method has access to all aspects of the request
    object, but its use of the response object is more limited:
    It can only write information to the ServletOutputStream or Writer of the
    response object and commit a response by writing content past the end of the
    response buffer, or by explicitly calling the flushBuffer method of the
    ServletResponse interface. It cannot set headers or call any method that affects
    the headers of the response. Any attempt to do so must be ignored.
    Does this mean that an included servlet must explicitly call flushBuffer method or its output must exceed the buffer size to send the output to client ?. I think what it means is that it should avoid flushing the buffer it at all possible.
    I think the reasoning behind this is that the responsibility for flushing the buffer/commiting the response should be with the including servlet, not the included one.
    Most of the time, the including servlet passes its own response object to the included servlet.
    The included servlet shouldn't automatically commit its output, because the servlet including it might want to veto it and send something different. So it should only flush the buffer when it has no choice - ie when it has no more room in the buffer, or the programmer tells it to explicitly.
    This leaves as much control of the response as possible with the including servlet.

  • Oracle 10g XE in tomcat 5.5 through JSP or Servlet

    Hello iam very new user of tomcat,oracle 10g .Will you please guide how to set environment variables and any other modifications to be done to run a JSP or Servlet including JDBC(oracle 10gXE) connection in tomcat5.5 for windows Xp.
    Please tell me in detail........................................

    I am sure that one can set up SELinux 'properly'.
    Everyone I talk to about SELinux tells me that it has become more detailed and much more 'secure' in that past years, and that probably explains why Oracle worked easily in FC3 and not so easily now. The added power also requires added configuration, which some have described to me as 'somewhat more involved than sendmail.cf'
    The documentation is at http://www.nsa.gov/selinux/ for those who wish to learn about the configuration capabilities. I'm sure that Google will also provide tutorials.

  • How to post a form to a servlet in CQ5.5?

    Hi all,
      I'm using CQ5 to develop some things. and now i am not so clearly how to post a 'FORM' and accept with a SERVLET.
      I've seen this 'http://forums.adobe.com/message/4932739#4932739' already, and try it. But once i add a new <input /> like :<input name="age" value="age" />.
    and i submit this form, then tell me error: javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}age
      see the code
       jsp:
         <!-- String action = /content/myproject/en/thanks   -->
        <form id="submitForm" method="post" action="<%= action %>.POST.html" onsubmit="return validate();">
            <input type="hidden" name=":redirect" value="<%=resourceResolver.map(action)%>" />
            <input type="hidden" name=":formpath" value="<%=currentNode.getPath()%>" />
            <input type="hidden" name=":formtype" value="<%=component.getResourceType()%>" />
            <input type="hidden" name="_charset_" value="utf-8" />
            <input name="age" value="26" />  <!-- if i comment this line, it can submit success, otherwise show me Status: 500. -->
            <input type="submit" value="Submit"/>
        </form>
      servlet:
        @Component(immediate = true, metatype = false, label = "QuestionnaireServlet")
       @Service
       @Properties(value = {
                        @org.apache.felix.scr.annotations.Property(name = "sling.servlet.methods", value = { "POST" }),
                        @org.apache.felix.scr.annotations.Property(name = "sling.servlet.resourceTypes", value = { "sling/servlet/default" }),
                        @org.apache.felix.scr.annotations.Property(name = "sling.servlet.selectors", value = { "POST" }),
                        @org.apache.felix.scr.annotations.Property(name = "sling.servlet.extensions", value = { "html" })
       public class QuestionnaireServlet extends SlingAllMethodsServlet implements
                        OptingServlet {
        protected void doPost(SlingHttpServletRequest request,
                                  SlingHttpServletResponse response) throws ServletException,
                                  IOException {
              //it seems never call this function.
    can anybody told me in details ?

    1).open the system/console/bundles and i can see the information of my servlet. include 'Symbolic Name', Version, Bundle Location, Exported Packages and so on.  I think it already a service. right ?
    2). change the selector to QAPOST for sling.servlet.selectors
    3). add the slash "/" then submit and the browser show me "403 Forbidden"
    4). without slash "/" before <action_attr_value>.POST.html, show me 'Status: 500', Message: javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}age

  • Appliation Server - HTML Include

    Hi
    I am using Jboss-4 application server in my local server.
    I would like to include a HTML file which is placed outside the web application (eg: sample.war) in a JSP.
    im using the following to include the HTML file
    <jsp:include page='<%=filepath%>'/>
    The issue is filepath is considered with reference to the application
    example:
    if filepath=/html/static/temp.html
    then JSP include tag is considering path as /sample/html/static/temp.html
    But the structure for the HTML file is C:/html/static/temp.html ( local hard disk )
    How to include the HTML file in such case?
    Please help.
    Regards
    Prakash A

    Have the jsp:include reference a Servlet. Pass in the filepath to the file as a parameter to the Servlet include. The servlet will use java.io to open the file, read in the file contents and write them to the response.
    <jsp:include page="fileServlet">     
       <jsp:param name="filepath" value="C:/html/static/temp.html" />     
    </jsp:include>

  • Plz help Me any one i am getting errors in Servlets

    My OS is Windows 2000.I am using J2SDK1.4.0_02(in c:\J2SDK1.4.02_02\) and in order to run the SERVLETS I recently installed the J2SDKEE1.3.1 (in c:\J2SDKEE1.3.1). I updated the class path to c:\ J2SDKEE1.3.1\bin and c:\ J2SDKEE1.3.1\lib\jsdk.jar .Now I wrote a simple servlet program SimpleServlet.java and saved it in c:\MyPrograms.
    Now when I compiled this program at prompt as follows
    C:\MyPrograms\>javac SimpleServlet.java
    I am getting the following errors
    1)Package javax.servlet doesn�t exist
    2)Package jaavx.servlet.http doesn�t exist
    Can somebody please tell me where I went wrong. My guess is that the problem is with installing J2SDK. Somebody please let me out this problem.
    Thanx!

    Okay, you installed the Enterprise java sdk. I have never seen this jar before: "J2SDKEE1.3.1\lib\jsdk.jar". There should be the j2ee.jar in the same folder, this is what contains the Servlet API.
    Next, when compiling your servlet include the classpath in your javac statement:
    javac -classpath %CLASSPATH% SimpleServlet.javaWhen installing the J2EE SDK, you should have set up your J2EE_HOME and J2EE_LIBS env entries. Rather than just add the jar to your class path, use the J2EE_LIBS ref when compiling instead:
    set J2EE_HOME=C:\J2SDKEE1.3.1
    set J2EE_LIBS=%J2EE_HOME%\lib
    javac -classpath %J2EE_LIBS%\j2ee.jar SimpleServlet.javaRather than call "set" each time add them to your System properties.
    Cheers,
    Anthony

  • Exceptions from nested includes not thrown to errorPage

    In our application a central dispatcher servlet includes JSPs.
              These JSPs include other JSPs. When an Exception is thrown from one of these
              pages it is not thrown, even when the error page is indicated in the
              included JSP with the page directive and the Exception is explicitly thrown
              from a catch block.
              I apprciate any thoughts.
              Thanks.
              -mc
              

    can u send the code snippet?
    "Abhishek" <[email protected]> wrote in message
    news:[email protected]..
    Hi
    I am having a stateless session bean(SLBean) which uses a singleton
    class(Single1). Both the SLBean and the Single1 are in the same jar
    file. Single1 contains a static method called getInstance() which
    returns the instance of the Single1(if not already existing).
    The probelm is that when I try to do the "Single1.getInstance()" from
    the stateless bean, then some exception( java.rmi.RemoteException:
    EJBException: ;nested Exception is: Java.lang.NullPointerException) is
    thrown.and getInstance() method of Single1 class in never invoked.
    What might be the problem? why am I not able to call my singleton
    class from the staless bean.
    Thanks in advance.
    Abhishek

  • 9iAS using 9iDS Forms servlet

    On my single machine, I am not interested in installing the infrastructure. I have 9iDS installed and I can run my forms app through my 9iDS supplied OC4J, port 8888. No prob.
    I want a simple way to run SSL with my forms app. My idea is install 9iAS (HTTP server, J2EE option) and have it front end my OC4J to more easily (than making OC4J do ssl) accomplish this.
    Can this work? If so, what are my steps?
    I tried modifying my oracle_apache file to point to my 9iDS forms servlet with a line like
    #Forms Servlet
    include "c:\oracle_9i\forms90\server\forms90.conf"
    My 9iAS is in a separate oracle home.
    regards,
    tt

    Frank,
    the Business Intelligence and Forms requires the 9iAS Infrastructure. As I indicated, I do not (gave up after trying for 2 weeks to install) have or want the infrastructure.
    I understand that J2EE provides HTTP server capability, but the effort to configure SSL would be easier with 9iAS than dinking with the OC4J xml and configuring keys, etc.
    So, I have 9iAS (no infrastructure) and 9iDS on the same machine. I noticed that 9iDS uses port 8888 and default 9iAS uses 7777 base. I am still trying. I am going to try a virtual host for my apache to 9iDS.
    Oh, I did get 9iAS to create and manage my Oracle9iDS OC4J instance. Now the trick is actually executing through it. Then I will turn on SSL.
    SUGGESTIONS STILL WELCOME!!
    regards,
    tt

  • RequestDispatcherObject.include(req,res) causing problem in welogic 9.1

    I am migrating my application from web7.1. to 9.1.
    In some servlets, i am using the RequestDispatcher.include method to paste a relevant JSP content.
    When I access the servlets parameters values only after the requestDispatcherObject.include(req,res), the parameter values are returned as null.
    For eg.
    consider 2 parameter values , status,mode are present in a servlet, project.java.
    I am including project.jsp file inside this servlet.
    When I access the parameters only after the include statement, the values are returned as null, but when i access any one parameters before this statement, both the original parameter values are retained.
    i.e.
    /Project?status=disp&mode=true
    Inside doGet method of Project .java:
    String mode=HttpServletRequest.getParameter("mode");
    RequestDispatcher reqdis=getServletConfig().getServletContext().getRequestDispatcher("/project.jsp");
    reqdis.include(req,res);
    String status=HttpServletRequest.getParameter("status");
    System.out.println("status "+status+"\nmode "+mode);
    The above code prints the value
    status disp
    mode true
    However when we change the code as ,
    RequestDispatcher reqdis=getServletConfig().getServletContext().getRequestDispatcher("/project.jsp");
    reqdis.include(req,res);
    String status=HttpServletRequest.getParameter("status");
    String mode=HttpServletRequest.getParameter("mode");
    System.out.println("status "+status+"\nmode "+mode);
    the output is
    prints the value
    status null
    mode null
    Thsi problem occurs in weblogic 9.1, and is otherwise working fine in weblogic 7.
    Do I have to make code change in all instances where this problem occurs , or is there any common solution.
    Kindly help me solve this issue at the earliest

    I tried reproducing this, and I don't observe the same behavior. I get the same values (those specified in the URL) regardless of whether I retrieve them before or after the include (or mixed as in your example).
              There is only one way I can think this might happen. If you are using HTTP POST and using getInputStream() or getReader() to read the body of the request, you could affect things. This is mentioned in the servlet spec. This would fit with your behavior. If your servlet reads a parameter, WLS will parse the all the parameters and they stay read-only (you can't set parameters, only attributes). WLS will only parse on demand for performance reasons (no point if one isn't requested). Nothing the included page can do will affect the parameters, so you'd see both be set. If the servlet includes the JSP first and the JSP calls getInputStream() and reads all the data, then when the servlet gets a parameter and WLS attempts to parse the POST body, there is no data left to be read (because the JSP already read it). Thus, everything will be null.
              But, in your example, it appears you are using GET. It shouldn't be possible if the parameters are set as part of the URL. And indeed, I don't see it.
              Perhaps your example is a simplification? What is your include doing?

  • RequestDispatcher.include causing some problem in Weblogic 9.1?

    I am migrating my application from web7.1. to 9.1.
              In some servlets, i am using the RequestDispatcher.include method to paste a relevant JSP content.
              When I access the servlets parameters values only after the requestDispatcherObject.include(req,res), the parameter values are returned as null.
              For eg.
              consider 2 parameter values , status,mode are present in a servlet, project.java.
              I am including project.jsp file inside this servlet.
              When I access the parameters only after the include statement, the values are returned as null, but when i access any one parameters before this statement, both the original parameter values are retained.
              i.e.
              /Project?status=disp&mode=true
              Inside <b>doGet</b> method of <b>Project .java</b>:
              <b>String mode=HttpServletRequest.getParameter("mode");
              RequestDispatcher reqdis=getServletConfig().getServletContext().getRequestDispatcher("/project.jsp");
              reqdis.include(req,res);
              String status=HttpServletRequest.getParameter("status");
              System.out.println("status "+status+"\nmode "+mode);</b>
              The above code prints the value
              <i>status</i> <b>disp</b>
              <i>mode</i> <b>true</b>
              However when we change the code as ,
              <b>RequestDispatcher reqdis=getServletConfig().getServletContext().getRequestDispatcher("/project.jsp");
              reqdis.include(req,res);
              String status=HttpServletRequest.getParameter("status");
              String mode=HttpServletRequest.getParameter("mode");
              System.out.println("status "+status+"\nmode "+mode);</b>
              the output is
              prints the value
              <i>status</i> <b>null</b>
              <i>mode</i> <b>null</b>
              Thsi problem occurs in weblogic 9.1, and is otherwise working fine in weblogic 7.
              Do I have to make code change in all instances where this problem occurs , or is there any common solution.
              Kindly help me solve this issue at the earliest

    I tried reproducing this, and I don't observe the same behavior. I get the same values (those specified in the URL) regardless of whether I retrieve them before or after the include (or mixed as in your example).
              There is only one way I can think this might happen. If you are using HTTP POST and using getInputStream() or getReader() to read the body of the request, you could affect things. This is mentioned in the servlet spec. This would fit with your behavior. If your servlet reads a parameter, WLS will parse the all the parameters and they stay read-only (you can't set parameters, only attributes). WLS will only parse on demand for performance reasons (no point if one isn't requested). Nothing the included page can do will affect the parameters, so you'd see both be set. If the servlet includes the JSP first and the JSP calls getInputStream() and reads all the data, then when the servlet gets a parameter and WLS attempts to parse the POST body, there is no data left to be read (because the JSP already read it). Thus, everything will be null.
              But, in your example, it appears you are using GET. It shouldn't be possible if the parameters are set as part of the URL. And indeed, I don't see it.
              Perhaps your example is a simplification? What is your include doing?

  • Registering Servlet in R12

    Hi,
    I have a requirement to call custom servlet from the OAF page.
    If anybody knows, how to register the custom servlet in the R12 help me.
    Thanks,
    Uma

    Hi Umma,
    Follow the following steps to include a servlet in a custom OAF page.
    1. create a servlet in your project.
    2. Note your URL pattern for your servlet class
    3. create a servlet include item in your page in jdev
    4. set URI property to servlet URL pattern
    for example TestServlet2 is your servlet class and its has URL pattern is /testServlet2 then your servlet include item URI propert will /testServlet2 .
    I hope it will solve your issue.
    Haroon

  • GetRequestURI() and jsp:include

    I have a page, a.jsp (referenced from http://server/app/a.jsp). This page has a line that looks like this:
    <jsp:include page="/app/foo/b.jsp" />
    Now, in b.jsp, I need to get the full URI (/app/foo/b.jsp). The request.getRequestURI() method returns the URI for the original page (a.jsp). I've tried a number of different things, but cannot come up with a way to retrieve this information that is independent of the JSP engine that I am using. Is this actually possible?
    Thanks!

    Hi jfeldmann,
    Did you have a look on
    1.
    javax.servlet.include.request_uri
    javax.servlet.include.query_string
    2.
    put in b.jsp to see
    <%=request.getAttribute("javax.servlet.include.request_uri")%>
    <%=request.getAttribute("javax.servlet.include.query_string")%>
    --Paul.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for