Results 1 to 10 of 10
  1. #1
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Redirect to jsp from Servlet using sendRedirect method

    need help... redirect to.jsp file from servlet.. here is my .jsp file location ..

    E:\J2EE\tomcat\webapps\Deepak\WEB-INF\classes\mvc\view\success.jsp
    E:\J2EE\tomcat\webapps\Deepak\WEB-INF\classes\mvc\view\error.jsp

    Here is my code:

    if(result){
    response.sendRedirect("success.jsp"); error.. success.jsp not available..
    return;
    }else{
    response.sendRedirect("error.jsp");--> error.. error.jsp not available..
    return;
    }

    How to specify the full path of .jsp file

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    The path to the JSP is from the root of the webapp.
    In your case it would be WEB-INF/classes/mvc/vies/success.jsp (or error.jsp).
    JSPs aren't normally put in the classes folder...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    I tried this still its not working..[HTTP Status 404-The requested resource () is not available.]

    if(result){
    response.sendRedirect("WEB-INF/classes/mvc/view/success.jsp"); Or ("/WEB-INF/classes/mvc/view/success.jsp");
    return;
    }else{
    response.sendRedirect("error.jsp");
    return;

  4. #4
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    Is there any connection with servlet package...? i mean this servlet class is inside package mvc.model; Here is the full code:-

    package mvc.model;

    import java.io.*;
    import java.net.*;
    import java.util.LinkedList;
    import java.util.List;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import mvc.helper.*;

    public class pass extends HttpServlet{

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    String userName;
    String password;
    userName=request.getParameter("userName");
    password=request.getParameter("password");
    int pass=Integer.parseInt(password);
    help hp=new help();
    boolean result=hp.check(userName,pass);
    if(result){
    response.sendRedirect("WEB-INF/classes/mvc/view/success.jsp");
    return;
    }else{
    response.sendRedirect("WEB-INF/classes/mvc/view/error.jsp");
    return;
    }
    }


    }

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    Don't post to old dead threads, don't hijack another poster's thread and don't ask the same question more than once.

    Do learn to use the code tags: BB Code List - Java Programming Forum

    The post you made in redirect to html page has been removed.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    Oh K sorry.. i was thinking i vill get my solution fast.. now i understood the rules.. :-)

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    JSPs are not packaged.
    Indeed it's quite possible this is because you have stuck your JSPs in with your classes (not sure since I have never worked on a project structured like that).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    I agree JSPs are not packaged.... OK lets make a change ... I changed my JSPs directory to E:\J2EE\tomcat\webapps\Deepak\WEB-INF\view\success.jsp..... now its shoud work still same 404 error..

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    Try forwarding rather than redirecting (I've only just noticed you're redirecting).
    The redirect call is as if the client has requested that resource, which the client browser is not allowed to do for something inside the WEB-INF folder.

    You'll want the RequestDispatcher from the request to do the forward.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Redirect to jsp from Servlet using sendRedirect method

    That's a point... Yea its working using RequestDispatcher.. thanks a lot :-)

Similar Threads

  1. redirect servlet page to html.
    By ayushi in forum Java Servlet
    Replies: 2
    Last Post: 07-23-2011, 08:57 PM
  2. redirect to a servlet page
    By niteangell21 in forum New To Java
    Replies: 5
    Last Post: 11-15-2010, 03:53 PM
  3. response.sendRedirect(url)
    By mutuah in forum Advanced Java
    Replies: 2
    Last Post: 08-07-2007, 02:56 PM
  4. help with response.sendRedirect method
    By katie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 03:22 AM
  5. How can I redirect in servlet?
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-14-2007, 06:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •