Solved

Redirection

Posted on 2001-06-21
13
291 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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
 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 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