Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Q about the servlet error dynamic handling  RSS feed

 
Tom Nicolas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have got puzzled in this point for days,help me plz..

there are two attribute in error class:
javax.servlet.error.status_code -- an integer object refers to the error page code
javax.servlet.error.message--a string refers to the error message show the client

doGet(......){
...
Integer code=(Integer)req.getAttribute("javax.servlet.error.status_code ");
String msg=(String)req.getAttribute("javax.servlet.error.message");
...
out.println(code);
out.println(msg);
..
}

and it told me that when call sendError(...) or setStatus(...) the Errorservlet instance will distill the error code and the error message and show them in the error page.
like this: res.sendError(res.SC_NOT_FOUND,msg);
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch!!!
So, what is the question?


Shrinivas
 
Tom Nicolas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i think the code:
...
Integer code=(Integer)req.getAttribute("javax.servlet.error.status_code ");
String msg=(String)req.getAttribute("javax.servlet.error.message");
...
out.println(code);
out.println(msg);
..

should be in a try/catch filed like this:

try{
...
}catch(FileNotFoundException e){
...
Integer code=(Integer)req.getAttribute("javax.servlet.error.status_code ");
String msg=(String)req.getAttribute("javax.servlet.error.message");
...
res.setError(code,msg); //i think the setError() should be invoked here.
out.println(code);
out.println(msg);
..
}

but all that codes are in a doGet() method.

doGet(......){
...
Integer code=(Integer)req.getAttribute("javax.servlet.error.status_code ");
String msg=(String)req.getAttribute("javax.servlet.error.message");
...
out.println(code);
out.println(msg);
..
}

it puzzled me
 
Tom Nicolas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if all codes were in the doGet(),it seems like any client visit this servlet by get method would always print the error code and message. But there is not exception.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still do not get what your question is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!