Solved

Redirection

Posted on 2001-06-21
13
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

717 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