Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

response already commited error

 
lavanya subramanian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i get an input from a HTML page to a servlet which
inturn invokes a bean and the result is forwarded to a
jsp page.
this.getservletContext().getRequestDispatcher("/Results.jsp").forward(req,res);
after this statement at forwarding,i get an error
saying "Meesage: Server caught unhandled exception
from servlet: Error: Cannot set header,Respponse
already commited"
i don't have any print or println statements in the code

any help would be appreciated.
thanks in advance,
bye,
lavanya
 
Manjunath Reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that the last line in ur method is
"this.getservletContext().getRequestDispatcher("/Results.jsp").forward(req,res);"
Unless you r using servlet chaining(which i believe weblogic 5.x doesnt allow), the request is specific to the initial servlet and ends with it. So if you try to divert the request from elsewhere..it throws this exception.
To be more precise with the solution can u paste your servlet code here.
thx
mpr


[This message has been edited by Manjunath Reddy (edited July 31, 2001).]
[This message has been edited by Manjunath Reddy (edited July 31, 2001).]
 
vipul makwana
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi subramanian
Try response.reset() before redirecting it.
It should work.
Vipul.
 
lavanya subramanian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,vipul and manju,
thanks for ur response
my servlet code is

public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException{
javax.servlet.ServletContext sc;
javax.servlet.RequestDispatcher rd;
try
{
com.examine.build.CustomerAccessBean customerAccessBean = null;
// instantiate the bean.
customerAccessBean =(com.examine.build.CustomerAccessBean) java.beans.Beans.instantiate(getClass().getClassLoader(),"com.examine.build.CustomerAccessBean");
request.setAttribute("customerAccessBean", customerAccessBean);
// Initialize the bean last_name property
if (!getParameter(request, "last_name", true, true, true, null).equals("")) {
customerAccessBean.setLast_name((getParameter(request, "last_name", true, true, true, null)));
}
// Invoke findByLastName action on the bean.
customerAccessBean.findByLastName(request.getParameter("last_name"));
sc=getServletContext();
rd = sc.getRequestDispatcher("/CustomerFindResults.jsp");
rd.forward(request,response);

}

catch(Throwable theException)
{
System.out.println("I'm here in catch");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html><body><h2>");
theException.printStackTrace();
pw.println("</h2></body></html>");
 
Bheemeswara Rao Amruthavakkula
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Once you forwarded the request you cant use any methods on response object.
remove the methods
"response.setContentType("text/html");
PrintWriter pw = response.getWriter();"
in catch block and try running your servlet. It should work fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!