epadilla
asked on
JSP Redirection
Hello everybody,
I'm working with servlets in a project. I have 5 servlets and I need the comunication between them. I am communicate them with the context and for initialize the servlets I 'm doing with the response.sendredirect(path ).
The trouble that I have its that I need to redirect the servlet to a jsp. I tried with getServletContext().getReq uestDispat cher("/SG_ ConfigServ Central.js p").forwar d(request, response); But I get an exception (java.lang.IllegalStateExc eption: WEB2645: Cannot forward after response has been committed) and I tried with include instead of forward but didn't work too.
Can anyone help me please?
Thanks a lot
I'm working with servlets in a project. I have 5 servlets and I need the comunication between them. I am communicate them with the context and for initialize the servlets I 'm doing with the response.sendredirect(path
The trouble that I have its that I need to redirect the servlet to a jsp. I tried with getServletContext().getReq
Can anyone help me please?
Thanks a lot
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Another comment, I am using the JBuilder and this exception only appear when I upload my project to iPlanet Web Server 6.0. Because when I compile in the JBuilder it works fine.
Thanks
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well I need to do the following:
Servlet1 is the base of all my project, and I want that Servlet1 communicate with Servlet2 for initialize some proccess, and I need that Servlet2 return the control to Servlet1, I did it with parameters, like this:
SERVLET 1
response.sendRedirect(Path
SERVLET 2
response.sendRedirect(Path
After that I need to display a JSP for the user.
Any other idea for try to do this??
doesn't sound like its a redirect you need, you cannot share processing between servlets.
once a servlet has redirected it should return.
once a servlet has redirected it should return.
At what line to you get the IllegalStateException, because after a sendRedirect you're not allowed to do anything as well. :-)
ASKER
Yes I did something with the response, because I did the response.sendRedirect(path
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
String stOption;
int inOption;
ServletContext scContext;
HttpServletResponse htResponse;
scContext = this.getServletConfig().ge
stOption = request.getParameter("para
inOption = Integer.parseInt(stOption)
switch (inOption)
{
case 0:
bsInitHostServlets(respons
if (inServletsCounter == -1)
{
asSpooler = (SG__Servlet) scContext.getAttribute("Se
bosSpooler = (SG__Servlet2) scContext.getAttribute("Se
sb_InitCloseSockets();
tbThreadVector.inInterface
tbThreadVector.inInterface
}
break;
case 2:
bs_voPrintSpooler();
break;
}
response.setContentType(CO
PrintWriter out = response.getWriter();
scContext.getRequestDispat
request, response);
public void bsInitHostServlets(HttpSer
IOException
{
String stPath = "";
stPath = bsReturnServletPath(inServ
if (stPath != "")
{
try
{
response.sendRedirect(stPa
inServletsCounter++;
}
catch (Exception e)
{
System.out.println(e.getMe
}
}
else
inServletsCounter = -1;
}
public String bsReturnServletPath(int inServletNumber, boolean boAllSer)
{
String stPath = "";
String stParam;
if (boAllSer == true)
stParam = "param0=0";
else
stParam = "param0=1";
switch (inServletNumber)
{
case 0:
stPath = "/sg_comms_servlet?" + stParam;
break;
case 1:
stPath = "/sg_servlet1?" + stParam;
break;
case 2:
stPath = "/sg_servlet2?" + stParam;
break;
}
return stPath;
}
Thanks a lot.