RequestDispatcher problem

Hi,
I have a jsp file which will call a servlet to update db. After update i transfer to a jsp file from servlet using RequestDispatcher.forward(req,res); It successfully go to the jsp file but the address bar in the IE display the same servlet and when i press refresh button it will execute the same servlet again. how can i solve this
reply immed
san

Don't use a request forward, use a response redirect.

Similar Messages

  • Forwarding JSP page through requestdispatcher problem in submiting form

    Hello everyone,
    I am very much new to servlet.
    My problem is somewhat this....
    when i am forwarding one JSP page by requestdispather , there is no problem.But after that when i am trying to submit one html form written inside the jsp page , the request is not submiting the jsp page rather it resides in the servlet.
    The code in servlet is
    RequestDispatcher rd =getServletContext().getRequestDispatcher("/applyConfirm.jsp");
    rd.forward(request,response);
    Now in (applyConfirm.jsp )jsp page one button is there , so when i will click that button the page has to be submitted.But its not submitting rather the request resides in the servlet.
    Dose someone will have any idea.
    Thanks in advance

    First check what sort of button you are using. It should be of "submit" type.
    Check the URL to witch URL it is submitting i.e. Action property in <FORM> tag.
    Make sure for the URLs in the client i.e HTML ex: href, action, and so on use the thumb rule of prefixing "<%=request.getContextPath()%>/" in your JSP or in servlet add it in the java code.
    This should solve the relative URL reference problem.
    Hope this helps.
    Cheers.

  • Servlet to Jsp RequestDispatcher Problem

    Hi All,
    I have come across a problem that wont allow me to post from a servlet to a jsp file.
    Here is the code im using. When i try to run it an internal error occurs.
    RequestDispatcher dispatcher;
    dispatcher = request.getRequestDispatcher("/Catalogue.jsp");
    dispatcher.forward(request, response);
    For some reason the dispatcher.forward(resquest, response) doesnt work.
    Can any one help me please?

    What happens? Do you get an error message in the browser? In your servlet log? If so, what's the error message. If not, what's the behavior like?

  • Servlet RequestDispatch problem

    I am using RequestDispatch to pass control from one servlet to another. My problem is that when I forward the request...
    It passes control to the next servlet which executes all the way through. But then passes control back to the calling servlet which executes the rest of its code from the forward method call and the first servlet is the one that outputs HTML. What am I doing wrong. I don't want the first servlet to regain control..
    RequestDispatcher dispatcher = m_request.getRequestDispatcher(url);
    dispatcher.forward(req,res);

    Do you want RequestDispatcher.forward() to act like System.exit()? I.E., the thread that is called is terminated? If you want the servlet calling forward NOT to execute after the call to forward then return after the forward is complete. Remember that you are forwarding the request, not (necessarily) the thread, so execution of your method will continue unless you explicitly exit.

  • Css and RequestDispatcher problem

    I'm using JBoss + embedded Tomcat (not using apache
    yet in development).
    I have problem with JSP and css. My JSP includes css
    with this tag:
    <link rel="stylesheet" href="style.css" type="text/css">If I access the JSP directly from web-browser IE5
    to http://127.0.0.1:8080/myContext/fileName.jsp ,
    it's displayed correctly.
    However, if I let a servlet dispatch the JSP, the css didn't
    included somehow (browser displayed the JSP without css-formatting).
    RequestDispatcher dispatcher = getServletContext().
                             getRequestDispatcher("/fileName.jsp");
        if (dispatcher != null)
            dispatcher.forward(request, response);
        /* ... */I put css and JSP in the same subdir. Is this a Tomcat error, or
    I forgot to set something in the request object, or
    I need to append something to "/fileName.jsp"?
    Thanks in advance.
    Verdi

    Unfortunately, the solution I found was to "hardcode" the absolute path. For example:<link rel="stylesheet" href="<%= request.getContextPath() %>/style.css" type="text/css">There're another way I think may preserve the context
    path, that is to use response.sendRedirect. Problem with
    this approach is however, you can't embedd javabean
    as "attribute" cause attribute will be removed in the new request (of redirected jsp).
    -- Verdi March --

  • Problems with tomcat 4.0.1

    hello,
    i�ve written some servlets using forte 3.0 with tomcat 3.2.
    everything works fine as long as I don�t run the servlets with tomcat 4.0.1.
    i use the request dispatcher / forward method - which dosn�t work reliable.
    it�s a list on which the user has to select one topic. the strange thing about it is that it works when you choose "back" after the error (dispatcher = null) has occured and select a different topic on that list - only the first choice makes en error.
    running on tomcat 3.2 with forte it works fine. but i get the following message in the tomcat output window:
    java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key dispatcher.forwardException
    and
    2002-01-13 11:40:05 - Ctx( /lg002234 ): Exception in: R( /lg002234 + /eingaben + null) - javax.servlet.ServletException: cannot find message associated with key : dispatcher.forwardException
    can somebody help?
    is use the dispatcher three times in that post-method - ist that a problem?

    ...sorry
    it�s not a problem with the requestdispatcher,
    problem is, that with tomcat 4.0.1 a parameter
    sometimes gets lost - but not with tomcat 3.2
    critical code is:
    String tierartAuswahl = request.getParameter("tierartAuswahl");
    is that a known bug of tomcat 4.0.1??

  • Problem with forward using RequestDispatcher

    Dear All
    Below is my code, which trying to use the RequestDispatcher.forward to go from a Servlet to a .jsp page.
    and use
    getServletContext().setAttribute("SvBio",vBio);
    to set an attribute
    It compiles finely but stuck at the forward request to the jsp page and through an exception which is given below.
    BUT on removing this statement
    getServletContext().setAttribute("SvBio",vBio);
    from my doget method , it works and forwrds to the next page
    please help me identifying the problem
    Thanks
    NAV
    ////Part of CODE////////////////
    Vector vBio;
    public void init()
    // vector vBio initialize in init()
    public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
    getServletContext().setAttribute("SvBio",vBio);
    if(param1 == bio)
    gotoPage("/jsp_pages/bio_gp.jsp", request, response);
    private void gotoPage(String address, HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(address);
    if(dispatcher !=null)
    dispatcher.forward(request, response);
    ///exception//////////////////
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
         at nav.gotoPage(nav.java:363)
         at nav.doGet(nav.java:319)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
         at java.lang.Thread.run(Thread.java:595)
    root cause
    java.lang.NullPointerException
         at org.apache.jsp.bio_gp_jsp._jspService(bio_gp_jsp.java:59)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
         at nav.gotoPage(nav.java:363)
         at nav.doGet(nav.java:319)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
         at java.lang.Thread.run(Thread.java:595)
    Apache Tomcat/4.1.29-LE-jdk14

    Thanks evnafets
    I find out null pointer assignment in jsp page where forward request was heading.
    There is one more question, if you help me a better understanding the issue
    I have a HTML page invokes the servlet by passing value of parameter, Servlet do some procesing and forward to JSP page depending on the incoming parameter,
    Can JSP page invoke the same servlet by passing some other parameter?
    I tried doing this, but it returns an empty page and didnt went back to servlet.
    HTML Page ---->Servlet--------> JSP page ---------> Servlet
    I think Forward method shift the control from the Servlet to JSP page and now its the responsibility of the jsp page to deliver the response to the client.
    Am i getting the empty page on invoking the servlet from the JSP page because I have not deliver the response to the client?
    ///the code of the JSP page is as fallows///
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>NAVTITLE</title>
    </head>
    <body link="#0000FF" vlink="#0000FF" alink="#0000FF">
    <td height="340" width="977">
    <p align="center"><font size="8" color="#001000"><b>biomolecular group           page</b></font></p>
    <%@page import="java.util.Vector"%>          
    <% Vector vBiopt = (Vector)getServletContext().getAttribute("SvBio");     
    out.println("\nThe size of vBio is ::"+vBiopt.size());
    int n = vBiopt.size();
    %>
    <p>This is the dynamic page generated for the biomolecular group</p>
    <%
    for(int k=0;k<n;k++)
    String href1 ="http://localhost:8080/nav/nav2?param2=";
    String item = (String)vBiopt.elementAt(k);
    out.println("<p><a href= \"" + href1 + k + "\">" + item + "</a></p>");
    %>
    </body>
    </html>

  • Context problems after RequestDispatch

    I have the following problem :
    we have two separate war files deployed on our server (on we developped and assembled, the other we get from an external company)
    We need to be able to communicate from a servlet from the first war file to jsp/servlet from the second war file.
    I've managed to do it with the following code
    ServletContext newCtx = ctx.getContext("/ctx2");
    RequestDispatcher dispatch = ctx.getRequestDispatcher("/URLServlet2");
    dispatch.forward(request,response);
    This works fine, until you trigger another request from the second servlet (also deployed in the second war file)
    The server tries to locate it under the first context.
    Anyone has an idea how to solve this ?
    Thanks in advance

    I assume that ctx.getRequestDispatcher("/URLServlet2") is a typo and you meant newCtx.getRequestDispatcher("/URLServlet2").
    What would happen if you did the samething in the second servlet?
    i.e. :
    In second servlet
    ServletContext newCtx = ctx.getContext("/ctx2");
    RequestDispatcher dispatch = newCtx.getRequestDispatcher("/URLServlet2");
    dispatch.forward(request,response);

  • Problems with RequestDispatcher.

    RequestDispatcher is not working as per the written documentation I have found. I am running tomcat on an AppServer. The following code is in a servlet found in directory /foo/WEB-INF/classes (browser access: http://localhost:8080/foo/servlet/myServlet):
    url="/foo/my.jsp" // I expected this to work
    url="/my.jsp"; // This does work
    getServletConfig().getServletContext().getRequestDispatcher(url).forward(request,response);     
    I would expect url="/foo/my.jsp" to return my.jsp. Rather, this code only works when url="/my.jsp". Since this is the case, I have not been able to find the correct path to forward to another servlet within the same directory.
    Any ideas/help would be greatly appreciated.
    w-                                   

    All servlets are accessable using a URL pattern such as "../servlet/ServletName". It does not matter where they are stored on the system. Servlets are not sent to the browser like HTML pages rather they are loaded and executed by the servlet container. Also, the application root directory should be omitted from any relative path. In your example you are using: getServletConfig().getServletContext().getRequestDispatcher("/foo/servlet/Hello2").forward(request,response); The problem is that a relative URL implies the web application root path so if you include it again it is redundant. Your example is the same as the following: getServletConfig().getServletContext().getRequestDispatcher("http://localhost:8080/foo/foo/servlet/Hello2").forward(request,response);The best way to think of it is to visualize the web-app root path added to the beginning of each relative URL. In otherwords think of "http://localhost:8080/foo/" added to the beginning of all relative URLs in the foo web app. So "http://localhost:8080/foo/" + "foo/servlet/Hello2" = "http://localhost:8080/foo/foo/servlet/Hello2". If you don't have a foo directory in the foo web-app then this request will fail. However: "http://localhost:8080/foo/" + "servlet/Hello2" = "http://localhost:8080/foo/servlet/Hello2". This will call the Hello2 servlet in the foo web-app. Post again if you are still confused.

  • 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?

  • RequestDispatcher and .jsp "first run" problem

    Hello all,
    I'm testing our app on a development server (rh 8.0, tomcat 4.1.18-LE-jdk14, apache 2.0.44, mod_jk-2.0.43 ). Everything seems to work fine except...
    I have several instances of servlets that call a .jsp, which calls a servlet, which calls another .jsp, etc. My problem is that the servlets have a problem referencing the .jsps the first time each one is called after a tomcat/apache restart. BTW, jsp to jsp calls work perfectly.
    For example, the log-in page calls a servlet which retrieves session and user info from a db and forwards the user to their "home page" that is built in .jsp. The first time I try to log in, I get the following error:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
         at com.act.cit.ui.CitGeneralServlet.gotoJSPErrorPage(CitGeneralServlet.java:119)
         at com.act.cit.ui.CitGeneralServlet.cleanUpForException(CitGeneralServlet.java:136)
         at com.act.cit.ui.CitLoginServlet.doPost(CitLoginServlet.java:201)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.servlets.InvokerServlet.serveRequest
    So not only am I not accessing the .jsp, but I'm not finding my desginated error .jsp either...looks like the 'null' that is being referenced is the .jsp I'm trying to hit. I've confirmed that the database is being accessed correctly (non-null results) and that I'm getting to the point in my servlet that forwards me to my .jsp:
    req.getRequestDispatcher("../jsp/citMain.jsp").forward(req, res);
    I've also tried:
    getServletContext().getRequestDispatcher("../jsp/citMain.jsp").forward(req, res);
    "req" and "res" both have non-null addresses. The next time I try to log in, everything works perfectly, just as it does on our old production server.
    All I can think of is that there's some sort of problem in the apache/tomcat config, but why would the server be able to process the .jsp successfully on subsequent tries?
    Thanks a lot! This one's really been eating at me!

    What version of tomcat and jdk are you using?rh 8.0, tomcat 4.1.18-LE-jdk14, apache 2.0.44, mod_jk-2.0.43
    I left my first getRequestDispatcher attempt as relative addressing and changed to absolute address on the second just to test:
    rd = req.getRequestDispatcher("../jsp/citMain.jsp");
    if (rd==null){  
         LogFileWriter.logThis(this, "rd was null");  //this is just a static logger I wrote  
         rd = req.getRequestDispatcher("/jsp/citMain.jsp");  
         if (rd==null)     
              LogFileWriter.logThis(this, "rd is still null");  
         else     
              LogFileWriter.logThis(this, "now rd is okay");
    else{  
         LogFileWriter.logThis(this, "rd was okay");
    } Here's my new logfile output after two login attempts:
    CitGeneralServlet--
    rd was null
    CitGeneralServlet--
    now rd is okay
    end of the first attempt, now here's the results of the 2nd attempt:
    CitGeneralServlet--
    rd was okay
    I still think it's odd that I can use relative addresses after the first execution, but I'm sure it's something to do with when the .jsp is compiled. Anyway, I don't have time to dig for the root cause right now. Absolute address seems to fix the problem, I'll stick with that. Thanks for all the suggestions. Hopefully this thread will help someone else who comes across the same problem.

  • Character Encoding Problem RequestDispatcher

    Hi Friends;
    I have a servlet and I use
    RequestDispatcher dispatcher = request.getRequestDispatcher(page);
                   response.setContentType("text/html;charset=UTF-8");
                   request.setCharacterEncoding("UTF-8");
                   PrintWriter out = response.getWriter();
                   //request.setCharacterEncoding("utf-8");
                   try {
                        dispatcher.forward(request, response);
                   } catch (ServletException e) {
                        e.printStackTrace();
                   } catch (IOException e) {
                        e.printStackTrace();
    for forward page. But if i forward a page, this pages' encoding isnot working. But if i refresh page it works.
    How can i handle this encoding.
    Thanks replies

    Hi Eray,
    It really doesn't make any sense (exept in very specific, well, exceptional cases) to call setContentType and/or getWriter on the response object before doing a forward (neither does calling setCharacterEncoding on the request object usually makes sense);
    request.getRequestDispatcher(page).forward(request, response);
    should be sufficient. I assume you forward to a jsp page? In case you want to enforce the response encoding of the content of the jsp page to be UTF-8, you can use this page directive at the top of your jsp page:
    <%@ page contentType="text/html; charset=UTF-8" %>
    I don't know why it does work when you refresh the page, maybe your browser configuration is not correct (in IE: Page/View > Encoding > Auto-Select)?
    Kind regards,
    Sigiswald

  • Problem wih a requestDispatcher

    Hi,
    I would want to know if it is incorrect to do in a form header :
    <form action='"+sc.getContext("/Players").getRequestDispatcher("/index.jsp")+"'></form>This would return a getRequestDistacher, but, could be asigned to a form a getRequestDistacher value or by the contrary the form needs a String to be asigned?
    Thanks with anticipation
    Edited by: bladu on Jul 10, 2008 11:31 AM

    hi,
    In the exercise I am doing the code I have written belongs to a servlet. I know that if I want to follow the MVC pattern, the form must go in a JSP, but in this case goes in a servlet.
    After all I want to go to the index.jsp of another resource ubicated in the server.
    But, that is other problem, because the application doesn`t run . Not because is incorrect, (I think so). The problem (related by other user) maybe that I have to edit one file , probably context.xml or server.xml and put "crossContext=true" to allow to go to one resource to another resource ubicated in the server. But I have been reading the documentation of Apache Tomcat (I have Tomcat 6.0.16 embebed in the Netbeans 6.1) and I am unable to resolve that problem.
    The problem is related there:
    http://forum.java.sun.com/thread.jspa?threadID=5311356&tstart=30
    Maybe you can give me your opinion about this problem.
    Thanks
    Edited by: bladu on Jul 10, 2008 1:05 PM

  • A problem with RequestDispatcher

    I have the following web.xml entry:
    <servlet>
                   <servlet-name>TestServlet</servlet-name>
                   <servlet-class>TestServlet</servlet-class>
                   <load-on-startup>1</load-on-startup>
              </servlet>     
              <servlet-mapping>
                   <servlet-name>TestServlet</servlet-name>
                   <url-pattern>/*</url-pattern>
              </servlet-mapping>

    In the future, please use the Edit button instead of hitting the back button and reposting the topic again.
    Continue here: http://forum.java.sun.com/thread.jspa?threadID=5240214

  • Unable to get RequestDispatcher for Context

    Eclipse 3.3.0
    Tomcat 6.0.16
    Java 1.5.0_13
    Mac OS X 10.5.6
    Greetings:
    I'm attempting to retrieve information cross context in my web application. I've attempted to enable cross context access by three means.
    - I've added "crossContext=true" to the <Context> element in the server.xml of the Tomcat configuration under the Servers project of my workspace.
    - I've added "crossContext=true" to the <Context> element in a META-INF/context.xml in the WebContent folder of my project.
    - I've added "crossContext=true" to the <Context> element of the context.xml file in the conf directory of the Tomcat installation directory.
    Yet despite these changes I'm still seeing "Unable to get RequestDispatcher for Context....Verify values and/or enable cross context access" in the console. What do I need to do to enable cross context access using Eclipse? Thanks for any help.
    ETA - I've had this working before. I believe that I upgraded to Tomcat 6 from Tomcat 5.5 and that's when the jstl cross context actions broke.
    ETA - I've got it working in Tomcat 6. The problem arises when I change the name of my webapplication from "foo" to ROOT inside eclipse. I want a jsp page in the ROOT web application to be able to access a servlet in the "bar" web application.
    Edited by: nantucket on May 17, 2009 2:17 PM
    Edited by: nantucket on May 17, 2009 2:26 PM

    Thanks for your reply evnafets.
    How many times do you declare your context???I know, I know... I got frustrated. :o)
    But seriously, since my post I've discovered that it is "working" but not in the manner I had expected within the IDE. That is, if I access the page at
    http://localhost:8080/ROOT/myPage.jspThen I can see the contents retrieved from the context bar. But if I use.
    http://localhost:8080/myPage.jspI can see that the page somehow has been deployed to the root context, but the error code 500 appears in place of where the content from the bar context should be.
    However, if I export war files for these two web applications and run them in Tomcat 6 outside of Eclipse, everything works as it should. So this is an eclipse issue with respect to deploying a web application to the root context. Maybe there is some configuration about that I must make somewhere.
    I hope that makes sense.
    Anyhow, the server.xml file contains the following..
    <Context crossContext="true" docBase="bar" path="/bar" reloadable="true" source="org.eclipse.jst.j2ee.server:bar"/>
       <Context crossContext="true" docBase="ROOT" path="/ROOT" reloadable="true" source="org.eclipse.jst.j2ee.server:ROOT"/>The jstl code in the jsp page accessing the context bar is the following.
    <c:import url='/helloworld?action=view' context='/bar' />

Maybe you are looking for

  • Extra wifi cost?

    I have a friend who has an iPhone 3G. In her system preferences, she only has 3G on, as opposed to wifi. The point being, she only uses the 3G network, as opposed to the iPhone automatically searching for networks, and joining open networks. The reas

  • How to reduce the image size of a quicktime in FCP

    Hi there, I am creating a DVD (DVD Studio Pro 3) containing mv2 of quicktime files. The screen size of these files vary according to the quicktime. I would like to give them all the same screen size so it looks even. At the moment some mv2 are full s

  • How do I plot 3 Y-axis in Microsoft Excel?

    This is probably more of a VB question but I thought someone here may have had to do this as well. I'm using the Report Generation toolkit to present my data in Excel. I have setup a template and call a couple of macros to format the worksheet. Thank

  • Something wrong with my iPhoto :-(

    Hello - I don't know if anyone is able to help. My file structure for iPhoto library is all over the place. I was trying to tidy it up. Now whenever I try to open certain photos from their thumbnail in iPhoto I just get a big, blurred exclamation mar

  • How to resize images but keeping proportion

    I have a lot of images at either square (500px), 500px width, or 500px height. What I am trying to do is to fit them into a 200 by 200 area. Now, the problem is that I am getting the images (their location rather) from a php database that I created.