servlet redirect problem help needed

servlet redirect problem help needed

package p;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Ser extends HttpServlet{
protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {

String location= null;
if(1<2){
location="/j1.jsp";
RequestDispatcher re=getServletContext().getRequestDispatcâ?¦
re.forward(req, resp);

}
location="/j2.jsp";
RequestDispatcher re=getServletContext().getRequestDispatcâ?¦
re.forward(req, resp);

}
}
this servlet is calling by a jsp..there is no problem,in this servlet the if condition always getting true coz 1<2...so the programme counter goes through the loop...and when the counter executes the line re.forward(req, resp);..it it redirect to jsp name j1....(as i knew when ever re.forward(req, resp); is execute the counter will move to the last location which is stored in string obj...but this is not happening coz after executing the re.forward(req, resp); inside the if loop it comes out and also execute the last portion of the code...and giving error 

i thought re.forward(req, resp); works like return means jumps to the response ...so rest of the code will not be executed

if any any one knows plz tell me what happens when the first re.forward(req, resp); executes...and what whappen when the last one also execute

ERROR

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.IllegalStateException: Cannot forward after response has been committed
p.Ser.doGet(Ser.java:23)
javax.servlet.http.HttpServlet.servicâ?¦
javax.servlet.http.HttpServlet.servicâ?¦
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
View Answers

Ads









Related Tutorials/Questions & Answers:
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatcâ?¦ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatcâ?¦ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
Advertisements
Java Servlet Problem - JSP-Servlet
, but in the attributeReplaced() method, i want to perform a redirect to another servlet... method. Please help!!  Hi friend, Please explain problem...Java Servlet Problem  I have a servlet class that implemets
Redirect from servlet to servlet
Redirect from servlet to servlet  I want to insert data from Text box... to redirectServlet , and from this servlet I want to again forward my page to insertServlet(i.e... or wex.xml needs to be mapped properly . Can anyone help please Its urgent
Help needed in JSP
Help needed in JSP  Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
help Needed with requirements
help Needed with requirements  Following are my requirements : * Maintain a student database *Based on a student's test results ,reports should be generated so as to project details such as a students weakness in a particular
redirect to multiple links from servlet
redirect to multiple links from servlet  hello , In my servlet page... the output in browser,i need to redirect to another link like the above line. i want redirect to multiple links simultaneously. anyone help me out
Java help needed
Java help needed  Create a web application that will allow a user... as needed by the number of characters of the chosen word. 2. Add 4 buttons or menu options: One for accessing help using the program, one for adding new words, one
Code Help Needed
Code Help Needed  I am trying to help a buddy of mine with this program and I can't seem to figure it out. I am still working on it but any help...[test]); line. Again thank you for any help. import java.util.*; import
urgent help needed!!!!
....please help me.... 1)state.jsp: <%@page import="java.sql.*"%>
urgent help needed!!!!
access country and state....please help me.... 1)state.jsp: <%@page import
Servlet problem
connectivity code it works but problem is with servlet page. My servlet code...Servlet problem  Hello, I am very shocked about this mysterious problem from last three month and now i hope rose india developers
servlet problem
servlet problem  wheni m deploying an servlet application im getting trouble context [/filename] startup failed due to previous error in tomcat 6.0.
Help needed for Form Validation please help!
Help needed for Form Validation please help!  I have created a page which has login as well as Signup fields. I validated the login part by using jsp.../password combination . Problem arises while validating the Sign up part as after
help needed - Java Interview Questions
help needed  What are the new features added in jdk 1.5?  Hi friend, The following were the new features added in java 1.5.... * Autoboxing/unboxing ------------------------- This link will help you
problem running a servlet on tomcat.
problem running a servlet on tomcat.  i have followed the steps given... be the problem? please help me out... to run my servlet that is placed in the directories as it has been mentioned here
look up values help needed
look up values help needed  Hi, I have a table that returns rows with a total weight (say 212.5 for example). I have another look up table that has... of 2.55 as 212.5kgs is between 195.5 and 220.5 can anyone help how I can do
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
please help me to this problem..
please help me to this problem..  i wrote a program like keyboard and i used [JTextFiled] means that just you can write inside the program (i.e inside the JTextField) but i want to make this program to let me write where i
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //bookâ??s title double price; //bookâ??s price
validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page... and password in my servlet against database and if not valid want to display error message saying "Invalid username and password" in my login page. please help
PLEASE HELP CAPTCHA PROBLEM
PLEASE HELP CAPTCHA PROBLEM  how can i make the captcha refresh autometically ???? please help this is <%@ Page Language="C#" %> <%@ Import Namespace="System.Drawing"%> <%@ Import Namespace
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   The Task Write a class whose objects will represent students. The class should have three fields for representing a studentâ??s
java servlet help neeed....
java servlet help neeed....  i have little bit miss concept on servlet and jsp....what ever i know always the jsp provoke first then servlet ...like... the servlet will be called (mapping i have to make in web.xml)......but to some one told
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   Write a class whose objects will represent students.The class should have three fields for representing a studentââ?¬â?¢s name, this studentââ?¬â?¢s
Help in completing Servlet code!
Help in completing Servlet code!  Complete the following Servlet codes to store the information read from the input form to session object. public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
Help me on the given problem of String
Help me on the given problem of String  class Test { string s1="Hello",s2="lo"; System.out.println((s1=="Hel"+"lo")); System.out.println((s1=="Hel"+lo)); } The above program prints true
Please Help - JSP-Servlet
. Thanks for your response.. You told me that its difficult to handle the problem.. Ok,Let me try my hands on it.. The help i need is can u please tell me..., in Home page. Then only u can get alert box in home page. Ur problem has
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok... This Problem With If...Else If...Else Statement But When the More Team Are There Then It's Large Codding So I Need To Help To Another Way To Do
Help needed on java standalone app and default browser interaction.
Help needed on java standalone app and default browser interaction.  Hi Developers and tutors, Is anyone able to guide on how am i able to extract...? Platform Windows Browser IE7 Any from of help would be deeply apperciated
java servlet connectivity problem with access
java servlet connectivity problem with access  Import java.sql javax.servlet //all packages entered try { Class.forName...=con.createStatement(); ^ i am confused what is the problem

Ads