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?

Similar Messages

  • Servlet / JSP caching problem!!

    I have a servlet that is running a process which creates an image. The servlet also is creating two jsp pages, one with a frameset for the header and body, and the other being the body. The body is supposed to dynamically use the new image, but it is cached and shows the old image until I manually hit the refresh button. In the servlet, I delete all the files / images before the process is run. When I had the image inside its own frame, I got it to work, but the client doesn't want it that way. I don't understand why it does not work now?

    I saw some topics about this problem in Servlets Forums in this site, try to find there.
    Forum Home > Servlet and JSP Technology.
    Good Luck,
    Jusbe

  • HELP: jsp cookie problem

    Hi,
    1) I have a page (index.jsp) that looks for a cookie, if the cookie isn't there it redirects to a login page.
    2) The login page, on submit, calls a servlet that sets the cookie (when usr and pwd are valid). Then the servlet redirects to the original page (index.jsp).
    3)The problem is, when redirected to the index.jsp, index.jsp cannot see the cookie -- so it redirects to login.jsp again. But if I refresh index.jsp it sees the cookie and works fine.
    So it looks like the cookie isn't totally set between the addCookie in the servlet and the load of the index.jsp. Is there so kind of "commit" or something I'm supposed to do after the "addCookie" to make it take correctly?
    Here are some code snippets -- any help is greatly appreciated!
    # the servlet
    response.addCookie(new Cookie("loggedin-username", sUsername));
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
    dispatcher.forward(request, response);
    # the index.jsp
    <%
         Cookie[] cookies = request.getCookies();
         boolean bLoggedIn = false;
         int i=0;
         while ( (cookies != null) && !bLoggedIn && (i<cookies.length) ) {
              if (cookies.getName().equals("loggedin-username")) {
                   Cookie c = cookies[i];
                   bLoggedIn = (c.getValue() != null);
              i++;
         if (!bLoggedIn) {
              response.sendRedirect("login.jsp");
    %>
    You are logged in.
    <p>

    2) The login page, on submit, calls a servlet that sets the cookie (when usr and pwd are valid). Then the servlet redirects to the original page (index.jsp).No the Servlet does a RequestDispatcher.forward to the index.jsp. A forward is a server side action that does not go to the browser and the target Servlet/JSP gets the original request and response objects.
    So in the Servlet you set the cookie.
    response.addCookie(new Cookie("loggedin-username", sUsername));Notice that you set it in the response object.
    Then the forward
    dispatcher.forward(request, response);And then the JSP looks for the cookie.
    Cookie[] cookies = request.getCookies();Notice it looks in the request for the cookies but since the response has not gone to the browser the browser has not had the opportunity to add the cookie into the request.
    Then the forward

  • User Authentication using Servlet and JSp

    Hi,
    I am developing a web app where i need to implement user Authentication to allow members to view and upload files on a certain directory say /data
    For this i am using a servlet as a controller which then forwads request to other jsps/servlets based on user response. I tried using servlet mapping in web.xml so that all browser requests would be directed to controller servlet and would branch from there on. However the problem all RequestDispatcher.forward() requests redirected to the servlet putting it in a loop.
    Is there another way to achieve this. (Apart from using form-based Basic Authentication).
    I am using Resin 1.2.8 servlet/jsp container.
    Any response as soon as possible would be appreciated.
    Thanks,
    Kushagra

    RequestDispatcher.forward() cause the HTTP request to be sent through the request processing flow as if the original request for the resource being forwarded to.
    It seems the servlet mapping you are talking about in web.xml should be made more specific. i.e. the mapping should be such that only your so called controller servlet will match up.
    You might want to specify the mapping for the controller servlet to be noticeably/effectively different from the mapping for other servlets and JSPs.

  • Please help..servlet calling JSP

    I have a servlet that for the time being (cut out all validation code...everything) is just trying to call a JSP. I keep getting The requested URL /servlet/hellos was not found on this server.---I'm running this at my local host, so it is not a path problem. the code is below.--
    Note..when I use getServletContext().getRequestDispatcher("/servlet/log"); this works (calling another servlet) but when the below is executed I get the error.
    package hellos;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class hellos extends HttpServlet {
    public void doGet (HttpServletRequest req, HttpServletResponse res)
         throws ServletException, IOException
              RequestDispatcher dispatcher =
              getServletContext().getRequestDispatcher("/ITS/itsLoginhtml.jsp");
              dispatcher.forward(req, res);

    Ok here is what is going on. I don't want to use redirect I want to use the dispatcher. The code is below and it works with redirect, but not dispatcher???? It says the URL cannot be found on server?????Can anyone help me get the dispatcher to work??
    package hellos;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class hellos extends HttpServlet {
    public void doGet (HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException
              res.sendRedirect("/ITS/itsLoginhtml.jsp");
              //RequestDispatcher dispatcher =
                        //getServletConfig().getServletContext().getRequestDispatcher("/ITS/itsLoginhtml.jsp");
              //dispatcher.forward(req, res);

  • Pass data from servlet to jsp using sendRedirect

    Hi,
    I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
    Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
    Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me know

    sendRedirect is meant as a true redirect. meaning
    you can use it to redirect to urls not in your
    context....with forward you couldn't pass information
    to jsps/servlets outside your own context.Actually, you can:
    getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
    Brian

  • Servlet and JSP in OAS

    I'm developing web application with OAS
    4.0.8.1 and JDeveloper 3.0 and I want to call
    JSP from servlet using "RequestDispatcher".
    I downloaded JSP for OAS from www.olab.com.
    In the Release note, there is a description
    about RequestDispatcher, but I cannot
    understand about details.
    In what configuration can I use servlet and
    JSP together with RequestDispatcher. Anyone
    scceeded about that?
    null

    wan (guest) wrote:
    : Hi everyone,
    : I am using OAS 4.0.8 on Solaris 2.6. After viewing servlet
    : and JSP samples, I am kind of confuse whether OAS supports the
    : following options
    : 1. JSP
    : 2. servlet chaining
    : 3. running JDeveloper DB Servlet wizard
    : (oracle.jdeveloper.servlet.*) and Java Business Objects
    : (oracle.jbo.rt.cs)
    : Thank you for your time.
    I found a white paper 408newfead.pdf, that says under "Future
    Directions" that it will add jsp support. I read somewhere (I
    can't remember where exactly :( ) that said 4.0.8.1 would
    support
    JSPs. I don't know if this release is out yet.
    I wish Oracle would get with the times and put out a product that
    is consistent with the technology they are touting as the
    future.
    Having us download Suns server to run servlets and JSP is
    ridiculous for the worlds second largest software company!
    null

  • JSP- Servlet-- Bean-- JSP how to implement

    I have problem.
    My JSP will take a emplyee id .
    Now I want to show all the values regarding that employee in a JSP(JSP form) from the DB(Oracle).
    So Iam planning like
    JSP-->Servlet-->Bean-->JSP
    So my doubts are.
    1. Is it correct approach
    2.If it is correct then which part of the flow connects to DB and stores the value before putting to JSP.
    Iam using Tomcat 4.31
    Plz help me

    I have problem.
    My JSP will take a emplyee id .
    Now I want to show all the values regarding that
    employee in a JSP(JSP form) from the DB(Oracle).
    So Iam planning like
    JSP-->Servlet-->Bean-->JSP
    So my doubts are.
    1. Is it correct approach
    2.If it is correct then which part of the flow
    connects to DB and stores the value before putting to
    JSP.
    Iam using Tomcat 4.31
    Plz help meHI
    What you are probably proposing is an MVC design pattern. I wonder if u have heard of the struts framework. Sruts uses MVC design pattern wherein the servlet u are talking about acts as a controller(C) and the bean acts as the model(M) .The JSPs present the view(V). Hence the name MVC.
    Your approach is right. First get the employee ID from the jsp and get the corresponding data from database(This logic u implement in the servlet). Then save the fetched data in a bean so that the result jsp can fetch data from it.
    Now this is not a strict MVC approach.
    Learn more about struts. It presents a much more cleaner solution.

  • Differences between WL or Netscape for Servlets and JSP's

    What are the advantages / disadvantages of running Servlets under WL,
              vs. say, running them in Netscape's servlet engine? Assuming EJB
              container is run separately, either one of these could make calls to the
              WL EJB server, so perhaps it would be simpler and faster to run servlets
              and JSP's under Netscape, and have them call via t3 into a weblogic
              server for EJB's?
              Thoughts
              david
              David Michaels <[email protected]>
              Director of Technology
              ShockMarket Corporation (650) 330-4665
              [david.vcf]
              

    David,
              One of the major reasons to run your servlets on Weblogic is that we have an
              optimization that allows us to pass by reference objects when calling from
              servlets to EJB. This makes things much faster.
              A number of our customers, in addition, have seen performance problems when
              using other servlet engines. It just seems to cause problems due to their
              threading models etc.
              Finally, our servlet engine is by far the most mature and robust on the
              market today. Our JSP implementation is also the best in terms of
              performance.
              Thanks,
              Michael
              Michael Girdley
              WLS Product Manager
              David Michaels <[email protected]> wrote in message
              news:[email protected]..
              > What are the advantages / disadvantages of running Servlets under WL,
              > vs. say, running them in Netscape's servlet engine? Assuming EJB
              > container is run separately, either one of these could make calls to the
              > WL EJB server, so perhaps it would be simpler and faster to run servlets
              > and JSP's under Netscape, and have them call via t3 into a weblogic
              > server for EJB's?
              >
              > Thoughts
              >
              > david
              >
              > --
              > David Michaels <[email protected]>
              > Director of Technology
              > ShockMarket Corporation (650) 330-4665
              >
              >
              

  • Wot all ways are there to call servlet from jsp

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanx

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanxhi here are few ways... to call servlet from jsp...
    these are just generic syntax.
    Form:     
    <form action="ServletPath">
    Link:     
    Directives & Action tags :
    <%@ page import="ServletPath" %>
         <%@ taglib uri="ServletPth" %>
         <jsp:include page="ServletPath">
         <jsp:forward page="ServletPath">
         <jsp:useBean class="ServletPath"> (Not sure about this useBean)
    hope you got your answer.
    regards,
    immu

  • Web.xml + jsp deployment problem

    Hi people,
    I have an eclipse project that has 1 servlet and 1 jsp page. I'm having problem in deployment. The servlet works fine but jsp is not accessible. The structure of my web.xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
         <display-name>IBNSubscriberServlet</display-name>
         <servlet>
              <description></description>
              <display-name>SubscriberServlet</display-name>
              <servlet-name>SubscriberServlet</servlet-name>
              <servlet-class>com.ibn.servlets.SubscriberServlet</servlet-class>          
         </servlet>
         <servlet-mapping>
              <servlet-name>SubscriberServlet</servlet-name>
              <url-pattern>/SubscriberServlet</url-pattern>
         </servlet-mapping>
         <servlet>
             <servlet-name>MonitoringG7</servlet-name>
             <jsp-file>/com.ibn.view.MonitoringG7.jsp</jsp-file>
         </servlet>     
         <servlet-mapping>
              <servlet-name>MonitoringG7</servlet-name>
              <url-pattern>/*</url-pattern>
         </servlet-mapping>
         <welcome-file-list>
              <welcome-file>index.html</welcome-file>
              <welcome-file>index.htm</welcome-file>
              <welcome-file>index.jsp</welcome-file>
              <welcome-file>default.html</welcome-file>
              <welcome-file>default.htm</welcome-file>
              <welcome-file>default.jsp</welcome-file>
         </welcome-file-list>
    </web-app>On requesting this JSP url, http://localhost:8080/IBNSubscriberServlet/MonitoringG7.jsp the http 404 status message comes which says the resource is not found. Cn someone please check the above jsp mappings in the web.xml file?
    Inside my "src", folder I have "com.ibn.view" which contains jsp file.
    thanks.

    this is how my web.xml looks like now.
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
         <display-name>IBNSubscriberServlet</display-name>
         <servlet>
              <description></description>
              <display-name>SubscriberServlet</display-name>
              <servlet-name>SubscriberServlet</servlet-name>
              <servlet-class>com.ibn.servlets.SubscriberServlet</servlet-class>          
         </servlet>
         <servlet-mapping>
              <servlet-name>SubscriberServlet</servlet-name>
              <url-pattern>/SubscriberServlet</url-pattern>
         </servlet-mapping>
         <welcome-file-list>
              <welcome-file>index.html</welcome-file>
              <welcome-file>index.htm</welcome-file>
              <welcome-file>index.jsp</welcome-file>
              <welcome-file>default.html</welcome-file>
              <welcome-file>default.htm</welcome-file>
              <welcome-file>default.jsp</welcome-file>
         </welcome-file-list>
    </web-app>If there is a mapping problem then the JSP should not work in tomcat as well, but it is. And i have just one servlet in the project and that is mapped my eclipse as above.

  • If true servlet to jsp

    Hi..
    If the condition is true in servlet i have to forward to new jsp page other other jsp page.
    Am accessing a parameter from html.the parameter is checked in servlet for verification using ifcondition.
    If the condition is true i need to forward to new jsp page.
    I have written code as below but it showing a blank page wen i run the page in netbean.
    ServletContext context=getServletContext();
    RequestDispatcher reqdis=context.getRequestDispatcher("menu.jsp");
    RequestDispatcher reqdis1=context.getRequestDispatcher("login.jsp");
    //condition checking the parameters
    if((users.equals(request.getParameter("user")))&&(passs.equals(request.getParameter("pass"))))
    reqdis.forward(request, response);
    else
    reqdis1.forward(request, response);
    the xml is
    <servlet>
    <servlet-name>Logverifier</servlet-name>
    <servlet-class>com.Logverifier</servlet-class>
    <servlet-mapping>
    <servlet-name>Logverifier</servlet-name>
    <url-pattern>/Logverifier</url-pattern>
    </servlet-mapping>
    </servlet>
    regards
    satheeh

    i think you have missed something in these two statements
    RequestDispatcher reqdis=context.getRequestDispatcher("menu.jsp");
    RequestDispatcher reqdis1=context.getRequestDispatcher("login.jsp");"/" yaar. you forgot to put this before your menu.jsp & login.jsp
    RequestDispatcher reqdis=context.getRequestDispatcher("/menu.jsp");
    RequestDispatcher reqdis1=context.getRequestDispatcher("/login.jsp");Diablo

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • How to combine servlet and jsp

    I'm doing a project. My friend using jsp. and i using servlet..
    we are confused, how to combine servlet and jsp. or we can just use redirect??
    but it's still doesn't work properly...thanks for your helpp

    You can use RequestDispatcher interface for calling a JSP from a Servlet, or vice-versa.
    Following is the code for sending output to a JSP page from a servlet:
    javax.servlet.RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(�/Ashu.jsp�);
    request.setAttribute(�Name�,�Ashutosh�);
    dispatcher.forward(request,response);
    - Ashutosh

  • How to  set the classpath for servlet and jsp???

    i add C:\tomcat-5.0\common\lib\servlet-api+jsp-api to the class path from DOS prompt, as show below:
    set CLASSPATH=%classpath%;C:\tomcat-5.0\common\lib\servlet-api.jar;C:\tomcat-5.0\common\lib\jsp-api.jar
    then, i compile the servlet:
    javac FirstServlet.java
    no error
    and i copy the .class file into C:\tomcat-5.0\webapps\servlets-examples\WEB-INF\classes
    i set the JAVA_HOME enviroment variable as below:
    set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_08
    i start the tomcat version 5.0 and run web browser and type http://localhost:8080/servlets-examples/servlet/FirstServlet
    i get the error message:
    HTTP Status 404 - /servlets-examples/servlet/FirstServlet
    type Status report
    message /servlets-examples/servlet/FirstServlet
    description The requested resource (/servlets-examples/servlet/FirstServlet) is not available.
    Apache Tomcat/5.0.30
    Can anybody tell me how to solve the problem. Thanks a lot.

    You will have to create the servlet mapping in the Web.xml file
    <servlet>
                 <servlet-name>FirstServlet</servlet-name>
                 <servlet-class>FirstServlet</servlet-class>
        </servlet>
    <servlet-mapping>
            <servlet-name>FirstServlet</servlet-name>
            <url-pattern>/servlet/FirstServlet</url-pattern>
        </servlet-mapping>

Maybe you are looking for