Solved

Redirection

Posted on 2001-06-21
13
285 Views
Last Modified: 2010-04-16
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....
0
Comment
Question by:bangviz
  • 3
  • 2
  • 2
  • +4
13 Comments
 
LVL 1

Accepted Solution

by:
tonus earned 50 total points
ID: 6213713
You got give the full URL address in
 response.sendRedirect ("welcome.htm");


ie: response.sendRedirect ("http://localhost:80/welcome.htm");


0
 

Expert Comment

by:anmadhu
ID: 6214211
Hi tonus,
Don't use
  response.Redirect('URL');

use

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

0
 

Expert Comment

by:anmadhu
ID: 6214212
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

0
 
LVL 2

Assisted Solution

by:vpadma
vpadma earned 50 total points
ID: 6214478
The URL must be absolute in the sendRedirect method(for example, https://hostname/path/file.html). Relative URLs are not permitted here.

Padma.
0
 
LVL 1

Author Comment

by:bangviz
ID: 6216569
It didn't work...i presume its failing at doGet method...
Awaiting for ur comments
0
 
LVL 1

Expert Comment

by:tonus
ID: 6217030
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:tonus
ID: 6217047
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.
0
 
LVL 2

Expert Comment

by:vpadma
ID: 6218250
How big is ur URL? in doGet, it cannot be more than 240 characters.

Padma.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6801175
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:

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

Thank you,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6814098
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
0
 

Expert Comment

by:CleanupPing
ID: 9062022
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.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9253880
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now