Results 1 to 6 of 6
  1. #1
    niteangell21 is offline Member
    Join Date
    Sep 2010
    Posts
    40
    Rep Power
    0

    Default redirect to a servlet page

    Guys, i am working on this java project where I am creating a web app. I have a home page for my web app where user can conduct queries.If user enters invalid data, the page is forwarded to an error page where the user is given a link to go back to the home page.But i dont know how to do the redirect through the link using servlet while keeping the session alive.

    These are my codes for ERROR page:

    Java Code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
    		response.setContentType("text/html");
    		
    		PrintWriter out = response.getWriter();
    		HttpSession session = request.getSession();
    		SearchBean search = (SearchBean) session
    				.getAttribute("search");
    	
    		
    		out.println("<h1><center>wrong input. try again!! </h1>" );
    		out.println("<a href=login.html>Click Here To Go Back </center>");
    	}

    right now, i am redirecting it to an html page, but i want to redirect to the home page which is a servlet. Plzz help..
    Last edited by niteangell21; 11-14-2010 at 09:52 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    That's not a redirect.
    That's a plain simple link.
    So, instead of giving the link to the login page, give it the link to the servlet, which will be mapped in your web.xml.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    Don't use servlet for user inputs.

    Do these things in jsp.
    Ramya:cool:

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    It's not doing user input, but it is displaying html...which would be better served as a jasp or html page, true. Actually, I'm not entirely sure what's going on with most of that code!

    Unless this is someone actually learning this stuff in the correct order, in which case they won't have done JSPs yet...:)

  5. #5
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi,
    we can able to redirect the error page by using "Request dispatcher forward".
    I hope this will help to you.
    Thanks,
    Selvaraj

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

Similar Threads

  1. redirect iframe if page cannot be displayed
    By moron3 in forum New To Java
    Replies: 1
    Last Post: 02-09-2010, 09:17 PM
  2. Redirect To Same Page
    By systech44 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-08-2009, 11:27 AM
  3. redirect to html page
    By simo_mon in forum Java Servlet
    Replies: 3
    Last Post: 02-12-2009, 05:18 PM
  4. Redirect page in web service
    By bluesheeva in forum Advanced Java
    Replies: 3
    Last Post: 02-03-2009, 11:56 PM
  5. How can I redirect in servlet?
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-14-2007, 05: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
  •