This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes response.sendRedirect help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "response.sendRedirect help needed" Watch "response.sendRedirect help needed" New topic
Author

response.sendRedirect help needed

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344
    
    2

Guys,

I was trying out a small example, I have a page called index.html which is a framed page and to the left frame I have several links with the first link pointing to index.jsp which will display in the right frame. Now in the right frame, i.e., in the index.jsp, I have a submit button and when I click submit button, it will go to a servlet and in that servlet I'm redirecting it to another jsp which is in the same location as this index.jsp. But when I tried this, it gives me a 404 error

Here is the code that I tried,


afterwhich I get a 404 error


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Which URL is the browser trying to access - does it exist?


Ping & DNS - my free Android networking tools app
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344
    
    2

yes, the addchoice.jsp lies in the same place as the other html and jsp files. I'm using frames...would that be any problem?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Well, my question was which URL the browser was trying to access, not which JSP page you think it should be accessing. If you're getting a 404, that means there is a disconnect between the two.
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
I note that all of your links are relative - "index.jsp" etc.
Except the one you are redirecting to which is an absolute link "/addchoice.jsp".

I think this is what Ulf is trying to establish by asking what URL is being requested.


28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344
    
    2

Ok, when I press submit in the index.jsp, this is the url that I see,

http://localhost:8084/Example/

It should have taken me to http://localhost:8084/Example/addchoice.jsp instead....right?? So what went wrong?
[ June 20, 2007: Message edited by: Jothi Shankar Kumar Sankararaj ]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344
    
    2

Example is my application's name. On loading, it will display index.html
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Originally posted by Jothi Shankar Kumar Sankararaj:
Ok, when I press submit in the index.jsp, this is the url that I see,

http://localhost:8084/Example/



Since the page you're working with is in a frame, what you see in the URL line is not what the browser just requested for that one frame. Do a right-click on the 404 page, and let the browser tell you which URL it accessed for that particular frame.
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

If the argument to sendRedirect() is a relative url with a leading '/', it is relative to servlet container root..
so you should specify your context root also in the URL..
your code should be

response.sendRedirect("/Example/addchoice.jsp");


- Marimuthu Madasamy
 
wood burning stoves
 
subject: response.sendRedirect help needed
 
Similar Threads
submit button is not working
Calling a form on a different frame
Jboss 5.1.0 jsp:root not working
problems in frame and struts!!!!
Viewing source code in frames.