Link to home
Start Free TrialLog in
Avatar of bangviz
bangviz

asked on

Redirection

Hi...

Is some something wrong as i'm unable to redirect....

=========================================================
import java.io.IOException;

import java.io.PrintWriter;

import java.io.Writer;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class ValidServlet extends HttpServlet {

  public void doGet (HttpServletRequest request,

                         HttpServletResponse response)

  throws ServletException, IOException {

 

     doPost (request, response);
     
  }        
public void doPost ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

      String username = request.getParameter ("john");

      String password = request.getParameter ("woo");

      if ((username == null) ||

           (password == null) ||

           (!username.equals("greg")) ||

           (!password.equals("bar"))) {   // Invalid login


           response.setContentType ("text/html");

           Writer w = response.getWriter();

           PrintWriter pw = new PrintWriter(w);

           pw.println ("<HTML><HEAD>");

           pw.println ("<Title>Invalid Login</Title>");

           pw.println ("</HEAD><BODY>");

           pw.println ("<C><H1>Invalid Login</H1></C>");

           pw.println ("Your login was invalid.<BR>");

           pw.println ("Please hit your browser's back button ");

           pw.println ("and try again");

           pw.println ("</BODY></HTML>");

      } else {

           response.sendRedirect ("welcome.htm");

      }

  }        
}

=====================================================
Please Pass ur comments....
ASKER CERTIFIED SOLUTION
Avatar of tonus
tonus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of anmadhu
anmadhu

Hi tonus,
Don't use
  response.Redirect('URL');

use

respond.setStatus(301);
respond.setHeader("Location","url");
respond.flushBuffer();
it will work perfectly.

Hi tonus,
Don't use
  response.Redirect('URL');

use

respond.setStatus(301);
respond.setHeader("Location","url");
respond.flushBuffer();
it will work perfectly.


bye bye
madhu

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bangviz

ASKER

It didn't work...i presume its failing at doGet method...
Awaiting for ur comments
I hope you are accessing the servlet by giving the correct URL. It works for me.

My host name is nrproj1 and I accessed the servlet using the URL
http://nrproj1/servlet/ValidServlet?john=greg&woo=bar
In the sendRedirect method I put the string as http://nrproj1/welcom.html.

And it worked fine.

If you are getting any error, please post that.
I hope you are accessing the servlet by giving the correct URL. It works for me.

My host name is nrproj1 and I accessed the servlet using the URL
http://nrproj1/servlet/ValidServlet?john=greg&woo=bar
In the sendRedirect method I put the string as http://nrproj1/welcom.html.

And it worked fine.

If you are getting any error, please post that.
How big is ur URL? in doGet, it cannot be more than 240 characters.

Padma.
bangviz--->  These are you open questions, please update and finalize them as quickly as possible.  If more is needed, let the experts know, if you've been helped please accept the expert comment that helped you to grade and close it.  Administration will be contacting you by Email about your lack of responsiveness to the experts who so willingly help you.  Your account has been escalated.

Experts, please let me know if this is still open in one week, and advise me how to close this ..... Award, PAQ at zero points or Delete.  Thanks in advance.

OPEN AND REQUIRE UPDATES/CLOSURE:

https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20091168 - MARCH, 2001
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20123325
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20139009
https://www.experts-exchange.com/jsp/qShow.jsp?ta=dbgen&qid=20067491 JANUARY, 2001
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20142040
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20139228
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20139036
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20125377

Thank you,

Moondancer
Community Support Moderator @ Experts Exchange
bangviz logged in 2/17, after this request was made but took no action on it.

PLEASE GUIDE ME HERE SINCE I WILL NOT NEED TO CLOSE THIS.  What is the fair outcome here to finalize this question.

Thanks,

EE Moderator
bangviz:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[split points between tonus and vpadma]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.