Solved

Redirection

Posted on 2001-06-21
13
282 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

758 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

23 Experts available now in Live!

Get 1:1 Help Now