ServletContext.getRequestDispatcher()

Hi,
I am having problem to forward jsp page request to static html page, or include static html page content in jsp response. The following is the jsp page I used to test,
<%
RequestDispactcher rd = application.getRequestDispatcher("/WEB-INF/hidden.html");
rd.forward(request, response);
%>
I tested this jsp on sunone webserver6.1 and tomcat5.5, I got the same error:
"getOutputStream() has already been called for this response"
If I rename hidden.html to hidden.jsp, all works fine.
I am trying to understand the meaning of a sentence regarding to the getRequestDispatcher() method from servlet 2.3 spec,
"If no servlet can be resolved based on the given path, a RequestDispatcher
is provided that returns the content for that path."
Here, what is exactly "the content for that path" ? is it the content of the .html file, or is it just the path string used to call the method ?
Or first of all, this method should not be used to deal with static .html file ?
Thanks,
Harry

You cannot use request dispatcher after using the
servlet outputstream.This is the complete content of the .jsp file,
<%@ page errorPage="/jsp/ErrorPage.jsp" %>
<%@ page import="javax.servlet.ServletContext" %>
<%@ page import="javax.servlet.RequestDispatcher" %>
<%
RequestDispatcher rd = application.getRequestDispatcher("/WEB-INF/hidden.html");
rd.include(request, response);
%>
As you can see from the source code, I do not explicitly use the [out]
or any output stream / writer in the .jsp source. The generated .java
file of the .jsp file does have statements like out.write() in it.
No matter how I write the .jsp file, I always see out.write() statements
in the generated .java file !

Similar Messages

  • Whats diff between servletcontext.getrequestdispatcher and request.getrequ

    Hi Everybody,
    Whats difference between
    servletcontext.getRequestDespatcher and requst.getRequestDespatcher I find that both resolve requested URIs in the same way on OC4J??

    Hi Kishore,
    A request copy applies only for customizing (client dependent) objects.
    A request tracks object modifications since its last transport. if the object is created in source system and included in a transport request, when it is transported to another system, it will create the object in target system. Then if you modify the  object, it will include modifications since last transport.
    As i said, a request copy is only valid for customizing objects. This is entries in tables, you will see that you have two kind of requests, customizing and workbench. Workbench objects are client independent, so request copy doesn't applies.
    it's very important to keep the order of requests when you transport and also not to delete requests in any system.
    Hope this helps (and hope it is clear, if you have any doubt, just ask!).
    Regards,
    Diego

  • Why getRequestDispatcher method cannot accept full URL?

    Examples*
    This code works well:
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
              String url = "/jsp/pageStart.jsp";
                    /* requestDispatcher is NOT null */
              RequestDispatcher requestDispatcher = getServletContext()
                        .getRequestDispatcher(url);
              requestDispatcher.forward(request, response);
         }This code doesn't work, get NullPointerException, requestDispatcher is null:
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
              String url = "http://localhost:8080/mymvc/jsp/pageStart.jsp";
                    /* requestDispatcher is null */
              RequestDispatcher requestDispatcher = getServletContext()
                        .getRequestDispatcher(url)
              requestDispatcher.forward(request, response);
    Notes*
    - JSP path is \src\main\webapp\jsp\pageStart.jsp
    - I am sure, I can manually open 'http://localhost:8080/mymvc/jsp/pageStart.jsp', just copy and paste this url into address of new browser window.
    - Base url is http://localhost:8080/mymvc/servlet/ControllerServlet
    - I use Servlet mapping:
    <servlet-mapping>
         <servlet-name>ControllerServlet</servlet-name>
         <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    <servlet>
         <servlet-name>ControllerServlet</servlet-name>
         <servlet-class>controller.ControllerServlet</servlet-class>
    </servlet>
    Questions*
    1. Why getRequestDispatcher method cannot accept full URL?
    2. Could you please explain to me the reason why ? and please provide me the better resolutions.
    Thanks u in advance!

    As per Java API documentation:
    ServletContext#getRequestDispatcher(String path)
    The pathname must begin with a "/" and is interpreted as relative to the current context root.
    For details: [http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)|http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)]
    ServletRequest.html#getRequestDispatcher(java.lang.String)
    To allow RequestDispatcher objects to be obtained using relative paths that are relative to the path of the current request (not relative to the root of the ServletContext), the getRequestDispatcher method is provided in the ServletRequest interface. The pathname specified may be relative, although it cannot extend outside the current servlet context.
    For details : [http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)|http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)]

  • How to properly handle Exception thrown in a .tag file?

    I've got a .jsp file that makes use of some custom tags, each defined in their own .tag file, and located in WEB-INF/tags. I'm having a lot of trouble with the scenario of cleanly dealing with an exception raised by scriptlets in either a .jsp file, and a .tag file. I'm using both Java and Tomcat 6....
    Originally, I wanted to use .tag files in order to componentize common elements that were present in .jsp pages, as well as move ugly scriptlets out of .jsp pages, and isolate them in tag files with their associated page elements.
    Things started getting hairy when I started exploring what happens when an exception is thrown (bought not handled) in a scriptlet in a .tag file. Basically, my app is a servlet that forwards the user to various .jsp pages based on given request parameters. The forwarding to the relevant .jsp page is done by calls to the following method:
    servletContext.getRequestDispatcher("/" + pageName).forward(request, response);
    Where 'pageName' is a String with the name of the .jsp I want to go to...
    Calls to this method are enclosed in a try block, as it throws both a ServletException, and IOException...
    When either my .jsp, or .tag throw an exception in a scriptlet, the exception is wrapped in a JSPException, which is then wrapped in a ServletException.
    I can catch this exception in my servlet... but then what? I want to forward to an error page, however, in the catch block, I can't forward in response to this exception, as that results in an IllegalStateException, as the response has already been committed. So what do I do? How do I get from this point, to my "error.jsp" page?
    It was suggested to me that I use the <% @ page isErrorPage="true" %> directive in my error.jsp,
    and the in my real .jsp, use <%page errorPage="/error.jsp" %>.
    This works great when the exception is thrown in my .jsp.... But when the exception is thrown in the .tag file... not so much...
    My .jsp page was rendered up until the point where the <my:mytag/> (the tag with the offending raised exception) was encountered. Then, instead of forwarding to the error page when the error in the tag is encountered, the error page is rendered as the CONTENT of of my TAG. The rest of the .jsp is then NEVER rendered. I checked the page source, and there is no markup from the original .jsp that lay below the my tag. So this doesn't work at all. I don't want to render the error page WITHIN the half of the .jsp that did render... Why doesn't it take me away from the .jsp with the offending tag altogether and bring me to the error.jsp?
    Then it was suggested to me that I get rid of those page directives, and instead define error handling in the web.xml using the following construct:
    <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error</location>
    </error-page>
    <error-page>
    <error-code>404</error-code>
    <location>/error</location>
    </error-page>
    For this, I created a new servlet called ErrorServlet, and mapped it to /error
    Now I could mangle the end of the URL, which causes a 404, and I get redirected to the ErrorServlet. Yay.
    However, exceptions being thrown in either a .jsp or .tag still don't direct me to the ErrorServlet. Apparently this error handling mechanism doesn't work for .jsp pages reached via servletContext.getRequestDispatcher("/" + pageName).forward(request, response) ????
    So I'm just at a total loss now. I know the short answer is "don't throw exceptions in a .jsp or .tag" but frankly, that seems a pretty weak answer that doesn't really address my problem... I mean, it would really be nice to have some kind of exception handler for runtime exceptions thrown in a scriptlet in .tag file, that allows me to forward to a page with detailed stacktrace output, etc, if anything for debugging purposes during development...
    If anyone has a few cents to spare on this, I'd be ever so grateful..
    Thanks!!
    Jeff

    What causes the exception?
    What sort of exception are you raising from the tag files?
    Have you got an example of a tag file that you can share, and a jsp that invokes it so people can duplicate the issue without thinking too much / spending too much time?
    My first instinct would be that the buffer is being flushed, and response committed before your Exception is raised.
    What you describe is pretty much standard functionality for Tomcat in such cases.

  • How to manipulate static string / text in HTML through Javascript

    Hi,
    Sorry I know this is not the perfect place to ask about HTML. But I need help somehow.
    In simple i am creating a website in JSP and using Javascripts.
    The problem is I have a HTML form where the user have to enter Login Id and Password. If user enters correct data then he is taken o relevant page.
    But if the user enters data (say some invalid character, where it can be handled by Javascript), then it should give feedback as Incorrect Id and Password in that page only but not by alert() statement i.e a statement with red font should get visible.
    Eg: In Yahoo the user taken to new page if he enters Wrong Id and Password
    In Gmail , the feedback is given on that page only.
    I hope u all understand.
    Thanks.

    If the action attribute of your login form say login.html is set to a servet, and say your servlet is responsible for the validation of Login Id and password, then you could use a RequestDispatcher object in your servlet.
    Use ServletContext.getRequestDispatcher(java.lang.String) to obtain the RequestDispatcher object and then invoke include() method on it.
    So, if Login ID and password do not match, then any message, will be included in the same login form, login.html
    Use google to find more information.

  • Possible to include a JSP in  a component response ?

    Hello,
    I am writing an UI component that needs to include a JSP in its response and I am having some issues with the include:
    In the encodeBegin() method of the component, I do the include like this:
    HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
    HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
    ServletContext servletContext = (ServletContext)context.getExternalContext().getContext();
    RequestDispatcher disp = servletContext.getRequestDispatcher(uri);
    disp.include(request, response);
    The called page is included in the response, but at the beginning of the page, not inside the calling component response. I am guessing it is because context.getResponseWriter() returns a different writer than the one obtained from the HttpServletResponse used in the included page, and that the 2 responses (the JSF and the included page) are assembled only when the JSF rendering is over.
    Has anyone been confronted to the same problem, and if so, have you been able to solve it ?
    Thanks in advance for any help.

    Hi,
    I suppose you have the same kind of problem discussed here
    http://forum.java.sun.com/thread.jsp?forum=427&thread=516289
    When you use includes, you have to use subviews and verbatims tags.
    The funny thing is, you'll probably encounter the verbatim tag bug, which was blocker for me, so I switched to MyFaces.
    Frederic

  • HTML result gets truncated after including of the JSF page

    Hi there,
    I'm trying to create a page that will include dynamically content of JSF pages from another web application.
    Thus, there is a web application (Pages) that is deployed under web context: /test-pages and another web application (Faces) that is deployed under web context: /test-faces.
    The source code of /test-pages/IndexPage.jsp
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
    <title>
    IndexPage
    </title>
    </head>
    <body>
    <h3>Page Start</h3>
    <jsp:include page="header.jsp"/>
    <br>
    <h1>Index Page of the test-pages application</h1>
    <br>
    <jsp:include page="footer.jsp"/>
    </body>
    </html>
    The source code of /test-pages/header.jsp
    <%
    ServletContext servletContext = request.getSession().getServletContext().getContext("/test-faces");
    RequestDispatcher reqDispatcher = servletContext.getRequestDispatcher("/faces/header.jsp");
    reqDispatcher.include(request, response);
    %>
    The source code of /test-pages/footer.jsp
    <h2>Simple Footer</h2>
    The source code of /test-faces/header.jsp
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <f:subview id="myID">
         <f:verbatim>
              <h2>Faces Header</h2>
         </f:verbatim>
    </f:subview>
    The HTML execution result (http://localhost:7001/test-pages/IndexPage.jsp):
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
    <title>
    IndexPage
    </title>
    </head>
    <body>
    <h3>Page Start</h3>
         <h2>Faces Header</h2>
    Could you help me understand, why the result gets truncated after including of the JSF page.
    Thanks,
    Sasha

    Thanks you for reply!
    Unfortunately, still no luck!
    Any other ideas will be highly appreciated!

  • How to solve java.io.IOException: Corrupt form data: premature ending

    hei evryone!
    Does anyone knows how to solve this bug?
    java.io.IOException: Corrupt form data: premature ending
    Im using Oreilly's cos.jar MultipartRequest
    here is my form :
    <FORM METHOD="POST" NAME="uploadform" action="mbbfile" ENCTYPE="multipart/form-data">
    <TR>
    <TD>Select a File:</TD>
    <TD><INPUT TYPE="FILE" NAME="srcfile" style="width:400px"/></TD>
    </TR>
    <TR><TD><INPUT TYPE="SUBMIT" VALUE="Send"/></TD></TR>
    </FORM>
    HERE IS mbbfile which is a servlet :
    package mbb.servlet;
    import java.io.IOException;
    import java.sql.Connection;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.oreilly.servlet.MultipartRequest;
    import org.jconfig.Configuration;
    import org.jconfig.ConfigurationManager;
    public class MBBFileServlet extends HttpServlet{
         private static final Configuration conf = ConfigurationManager.getConfiguration("ConfigFile");
         public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              String filePath = conf.getProperty("FilePath", "", "test");
              try{
              MultipartRequest multi = new MultipartRequest(req,filePath,5*1024*1024);
              }catch(Exception e){
                   System.out.println("MBBFileServlet Exception ---> "+e.getMessage());
         public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              doGet(req,res);
    Sometimes it works meaning the file is uploaded in the directory without any exception, sometimes the file is uploaded but with exception on the log saying "MBBFileServlet Exception ---> Corrupt form data: Premature Ending". and sometimes the files is not uploaded at all and when i check the error is : "MBBFileServlet Exception ---> Corrupt form data: Premature Ending". Can anyone please help me on this matter. Thx!
    Your response would be deeply appreciated.
    br,
    TAC

    Hi all!
    Since I've spent some days now trying to figure out what was wrong with my file upload in Struts 1.1, I would like to share my solution with the rest of you in order to spare you for the same amout of wasted time I've spent :-)
    My platform is Resin 3.0.8 and Struts 1.1. My problem was that JPEG's got corrupted when arriviving at the server. After a few days searching on the net, I tried with a plain servlet and the O'Reilly package, and the app worked perfect.
    Here is my servlet:
    package no.yourcompany.yourapp.servlet;
    import com.oreilly.servlet.multipart.MultipartParser;
    import com.oreilly.servlet.multipart.Part;
    import com.oreilly.servlet.multipart.FilePart;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.ServletException;
    import javax.servlet.ServletContext;
    import javax.servlet.RequestDispatcher;
    import java.io.IOException;
    import java.io.ByteArrayOutputStream;
    public class ImageUpload extends HttpServlet {
    private static final String PAGE_RECEIPT = "/popImageUploadReceipt.do";
    private static final int MAX_FILE_SIZE_IN_BYTES = 10000000; // 10 M
    * Extracts image from request and puts it into person form.
    * @see HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    // custom beans from my project, not defined here
    PersonRegistrationForm personRegistrationForm = null;
    PortraitImage portraitImage = null;
    ByteArrayOutputStream outputStream = null;
    Part currentPart = null;
    FilePart currFilePart = null;
    personRegistrationForm = (PersonRegistrationForm) request.getSession().getAttribute(DsnSessionKeyConstantsIF.KEY_PERSON_FORM);
    portraitImage = personRegistrationForm.getPortraitImage();
    try {
    MultipartParser parser = new MultipartParser(request, MAX_FILE_SIZE_IN_BYTES);
    while ((currentPart = parser.readNextPart()) != null) {
    if (currentPart.isFile()) {
    currFilePart = (FilePart) currentPart;
    outputStream = new ByteArrayOutputStream();
    currFilePart.writeTo(outputStream);
    // portraitImage is just a bean for encapsulating image data, not defined in this posting
    portraitImage.setContentType(currFilePart.getContentType());
    portraitImage.setImageAsByteArray(outputStream.toByteArray());
    portraitImage.setOriginalFileName(currFilePart.getFileName());
    break;
    } // if (currentPart.isFile())
    } // while ((currentPart = parser.readNextPart()) != null)
    } catch (IOException ioe) {
    // noop
    // redirect to receipt page
    ServletContext servletContext = this.getServletContext();
    RequestDispatcher requestDispatcher = servletContext.getRequestDispatcher(PAGE_RECEIPT);
    requestDispatcher.forward(request, response);
    } // doPost
    } // ImageUpload
    AND ADD THIS TO YOUR WEB.XML
    <servlet>
    <servlet-name>ImageUpload</servlet-name>
    <servlet-class>no.yourcompany.yourapp.servlet.ImageUpload</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ImageUpload</servlet-name>
    <url-pattern>imageUpload.do</url-pattern>
    </servlet-mapping>
    AND THE HTML-FORM IS HERE
    <form action="/yourapp/imageUpload.do" method="post" enctype="multipart/form-data" accept="image/*">
    <p>
    <input type="file" name="portraitImage" />
    </p>
    <p>
    <input type="image" src="/dsn/img/btn_last_bilde.gif" border="0">
    </p>
    </form>

  • Path login does not start with a "/" character

    I get a "java.lang.RuntimeException: Path login does not start with a "/" character" in my WebApplication.
    - Http Status 500
    - The server encountered an internal error () that prevented it from fulfilling this request.
    Instead I excepted the site for a Re-Login (timout after 10 min), What's wrong?
    The server I use is: Sun Java System Application Server Platform Edition 8.0 (build b57-fcs)
    Here is the full StackTrace:
    [#|2004-05-26T14:50:50.609+0200|SCHWERWIEGEND|sun-appserver-pe8.0|javax.enterprise.system.container.web|_ThreadID=17;|Standard
    WrapperValve[OwaFolderTree]: Servlet.service() for servlet OwaFolderTree threw exception
    java.lang.RuntimeException: Path login does not start with a "/" character
    at org.apache.catalina.core.ApplicationContextFacade.doPrivileged(ApplicationContextFacade.java:451)
    at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:255)
    at com.space2go.icafe.S2GHttpServlet.service(S2GHttpServlet.java:3260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
    at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:289)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:205)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:283)
    at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:102)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:192)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:261)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:200)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:180)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:582)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
    at com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java:134)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
    at com.sun.enterprise.security.web.SingleSignOn.invoke(SingleSignOn.java:272)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
    at com.sun.enterprise.web.VirtualServerValve.invoke(VirtualServerValve.java:209)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:161)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
    at com.sun.enterprise.web.VirtualServerMappingValve.invoke(VirtualServerMappingValve.java:166)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:979)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:692)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:647)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:691)
    at java.lang.Thread.run(Thread.java:534)

    It looks like you are getting this error when trying to use the RequestDispatcher. There are two different flavors of the RequestDispatcher :ServletRequest.getRequestDispatcher that will take a relative path and ServletContext.getRequestDispatcher that will only take absolute paths (ie start with a '/').
    If yoy are trying the use the second version of RequestDispatcher you'll need to adjust the path to an absolute path.
    http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html

  • Issue upon upgrading from 10.1.2 to 10.1.3.3

    Hi,
    i am upgrading the AS from 10.1.2 to 10.1.3.3,
    i have deployed the same ear on oc4j 10.1.3.3 which i have deployed on 10.1.2
    the issue is, upon session time out on 10.1.3.3 it give error and doesn't redirect to session expire page(defined in web.xml) but the same ear works fine on 10.1.2 :
    error message is :
    java.lang.IllegalArgumentException: path must begin with a "/"     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:1668)     at com.bidm.misc.service.bo.SessionExpireFilter.doFilter(SessionExpireFilter.java:99)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.AJPRequestHandler.run(AJPRequestHandler.java:302)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.AJPRequestHandler.run(AJPRequestHandler.java:190)     at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)     at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)     at java.lang.Thread.run(Thread.java:595)
    Thanks,
    DJ

    hi steve,
    yes i am using a filter to handle the session timeout, here is the code in web.xml
    root context for the application is: /MyApp
    location for expire.jsp is : /MyApp/expire.jsp
         <filter>
              <filter-name>SessionExpireFilter</filter-name>
              <filter-class>com.myapp.SessionExpireFilter</filter-class>
              <init-param>
              <param-name>redirect</param-name>
              <param-value>expire.jsp</param-value>
              </init-param>
         </filter>
         <filter-mapping>
              <filter-name>SessionExpireFilter</filter-name>
              <url-pattern>*.jsp</url-pattern>
         </filter-mapping>
    code for SessionExpireFilter.java:
    public class SessionExpireFilter implements Filter {
    private static boolean no_init = true;
    private static Log log = LogFactory.getLog(SessionExpireFilter.class);
    private FilterConfig config;
    private String redirect;
    public SessionExpireFilter() {
    redirect = null;
    public void init(FilterConfig filterconfig) throws ServletException {
    config = filterconfig;
    no_init = false;
    initRoute();
    public void destroy() {
    config = null;
    public void doFilter(ServletRequest servletrequest,
    ServletResponse servletresponse, FilterChain filterchain)
    throws IOException, ServletException {
    HttpServletRequest httpservletrequest = (HttpServletRequest) servletrequest;
    HttpSession httpsession = httpservletrequest.getSession(true);
    if ((httpsession == null) ||
    (httpservletrequest.getRequestedSessionId() == null) ||
    (redirect == null)) {
    if ((httpservletrequest.getRequestURI().indexOf("login.jsp") != -1) ||
    ((httpservletrequest.getRequestURI().indexOf("bookingAdviceAction.do") != -1) &&
    (httpservletrequest.getParameterMap() != null) &&
    httpservletrequest.getParameterMap().containsKey("servletAction")) ) {
    filterchain.doFilter(servletrequest, servletresponse);
    } else {
    //session is expired
    RequestDispatcher requestdispatcher = config.getServletContext().getRequestDispatcher(redirect);
    requestdispatcher.forward(servletrequest, servletresponse);
    } else {
    // session is expired
    HttpServletResponse httpservletresponse = (HttpServletResponse) servletresponse;
    ServletContext servletcontext = config.getServletContext();
    // It won't happen so frequent
    if (getRedirect(redirect)) {
    httpservletresponse.sendRedirect(redirect);
    } else {
    // these jsp won't be filtered, login.jsp & index.jsp
    if ((httpservletrequest.getRequestURI().indexOf("login.jsp") != -1) ||
    (httpservletrequest.getRequestURI().indexOf("index.jsp") != -1)) {
    filterchain.doFilter(servletrequest, servletresponse);
    } else {
    RequestDispatcher requestdispatcher = servletcontext.getRequestDispatcher(redirect);
    requestdispatcher.forward(servletrequest, servletresponse);
    public void initRoute() {
    //log.debug("in initRoute");
    redirect = config.getInitParameter("redirect");
    if (redirect == null) {
    if (log.isDebugEnabled()) {
    log.debug(
    "Session Expire filter: could not get an initial parameter redirect");
    redirect = "expire.jsp";
    private boolean getRedirect(String s) {
    //log.debug("in getRedirect");
    int i = s.indexOf(":");
    if (i <= 0) {
    return false;
    } else {
    String s1 = s.substring(0, i).toUpperCase();
    return s1.startsWith("HTTP");
    Thanks,
    DJ

  • Background processing spawned from a servlet

    I have need to get data from a slow source with every login to my site, and don't want to make the customer wait for the retrieval of all the data before being logged in. I have tried creating threads from a servlet that will get this information, and then having the servlet wait up to 8 seconds before giving up on the data coming back and just going on. This works fine, except for what appears to be a memory leak resulting from threads the app server does not account for.
    Does anyone have ideas of how to do this?

    You can do this by 'including' the JSP.
    servletContext.getRequestDispatcher(url).include(request, response);

  • Existing session is becoming null when returning from jsp

    Hi Guys !
    I have an urgent requirement to meet in few days from now and got stuck with session problem in servlet.
    Scenario :-
    For the first time when i call a servlet a new sessoin is created and after some validations i forward to a jsp which has some links.
    I have printed sessoin ids from both the servlet and jsp and they are same.
    Now when i clicked on the link in jsp , the servlet is called but session is lost its becoming null.
    Servlet Code :
    HttpSession session = request.getSession(false);
    if(session ==null){
    // create session code ....using getSession(true)
    RequestDispatcher r = servletcontext.getRequestDispatcher(resp.encodeURL("/user.jsp"));
    jsp code:-
    <a href="<%=response.encodeURL(/application/servlet/ViewUser") %">" > View User </a>
    GUYS GIVE ME A SUGGESTION IN THIS REGARD AS SOON AS POSSIBLE .....
    Thanks in advance !
    Aparna</a>

    Hi,
    Session Create Code in Login file
    HttpSession hs = req.getSession( true );
    hs.setAttribute( "user", lb.getUsername() ); // username() is ur unique id
    Session Tracking code in all file
                   HttpSession hs=request.getSession();
                   if ( hs == null || hs.getAttribute( "user" ) == null )
                        response.sendRedirect ( "./index.jsp" );
    Logout code
    HttpSession hs=req.getSession(false);
                   hs.setAttribute( "user", null );
                   hs.invalidate();
                   res.sendRedirect ( "./index.jsp" );
    // I hope this snippet will help u..

  • Forward to .pdf

    Hi, I post this question a while back but no bites, so i'm trying again.
    I need to forward my servlet to a pdf but I cant seem to get it to work. Here is the code:
    if(servletContext.getRequestDispatcher(template) != null){
      while(!resp.isCommitted())
        servletContext.getRequestDispatcher(template).forward(req, resp);
    //template being the path to file
    Thanks

    My servlet cant seem to find the pdf and so nothing gets opened. Is this a normal procedure for forwarding to a pdf file or is there another method for doing this?

  • Help with how to forward the page from the serlet

    Hello,
    I previously post this page in a different place, sorry about that, however, i have small problem in forwarding servlet,
    here is my servlet class
    public class UploadTransferServlet extends HttpServlet {
             public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
              HttpSession session = request.getSession(true);
              UploadTransferForm uForm     = (UploadTransferForm)session.getAttribute("form");
              Session sess = null;
              try {
                   sess = Waterfind.getSessionFactory().openSession();
              } catch (net.sf.hibernate.HibernateException e) {
                   logger.error("Error opening hibernate session", e);
              try {
              } catch (Exception e) {
                   logger.error("Error adding image to the database", e);
                   try {
                        sess.close();
                   } catch (net.sf.hibernate.HibernateException ee) {
                        logger.warn("Exception closing session", ee);
              if (sess != null) {
                   try {
                        sess.close();
                   } catch (net.sf.hibernate.HibernateException e) {
                        logger.warn("Exception closing session");
              ServletContext servletContext = this.getServletContext();
              RequestDispatcher requestDispatcher = servletContext.getRequestDispatcher(uForm.getForward());
              logger.debug("forwarding " + uForm.getForward());
              requestDispatcher.forward(request, response);
         } // doPost
    } // ImageUploadand i do get forwarding /admin-add-trasnfer-form.html?formId=30402
    in my log f ile,
    however, in browser, it wouldnt forward to the page.. why is that?
    only half of the page load up, inc the html header,
    and address bar, it shows the servlet name.. not the actual page,
    how do i get to load the complete page,
    and is there is a way to update the actual page address in the address bar as well?

    i found the problem. its a jsp related problem, not wasnt getting the id, fixed it, thanks :)

  • Parameter passing from Java to Jsp

    Hi all,
    I have an XML and a Java class. I have taken some values from XML into my Java class. Now I want to pass these parameters to a Jsp and display it as a link tag.
    Somebody please help me...

    You add them to the servlet Request object as attributes, then you use ServletContext.getRequestDispatcher(uri).forward(request, response) to transfer to the jsp.
    It's usually cleanest to use some kind of bean as a "Data transfer object" so that all your stuff goes accross as one attribute and you can get it with <jsp:useBean >

Maybe you are looking for