Can I invoke a JSP error page from a servlet?

Yes, you can invoke the JSP error page and pass the exception object to it from within a servlet. The trick is to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute. However, note that you can do this from only within controller servlets.If your servlet opens an OutputStream or PrintWriter, the JSP engine will throw the following translation error:java.lang.IllegalStateException: Cannot forward as OutputStream or Writer has already been obtainedThe following code snippet demonstrates the invocation of a JSP error page from within a controller servlet:protected void sendErrorRedirect(HttpServletRequest request,HttpServletResponse response, String errorPageURL, Throwable e) throwsServletException, IOException {request.setAttribute ("javax.servlet.jsp.jspException", e);getServletConfig().getServletContext().getRequestDispatcher(errorPageURL).forward(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response){try {// do something} catch (Exception ex) {try {sendErrorRedirect(request,response,"/jsp/MyErrorPage.jsp",ex);} catch (Exception e) {e.printStackTrace();}}}

Showing Answers 1 - 6 of 6 Answers

pulipaka

  • Oct 6th, 2005
 

I have some doubts about these questions given below.

1. How do u difine an error page?

2.What r the methods called in servlet life cycle?

3.How can u make session variables un available?

4. How to change the port no of agiven application server?

5.How do udeploye an EJB in the existing application using webspehere?

6.Why and in wat kind of requirments we need to use EJBs?

  Was this answer useful?  Yes

pulipaka

  • Oct 6th, 2005
 

1.wat is entity context?

2.How can i send user authentication by using URL connection?

3.can we use constuctor instead of init()to initialize the servlet?

4.How information passed from jsp to the included jsp?

5.can we declare overriding as int?

6.diff b/w RequestDispacher rd=getServletContext.getRequestDispacher()

and  diff b/w RequestDispacher rd=request.getRequestDispacher()

  Was this answer useful?  Yes

pulipaka

  • Oct 6th, 2005
 

1.wat is defult value in java?

2.in a class there is 3 mathods how can we call that methods in a servlet?

3.Where we use abstract class?

  Was this answer useful?  Yes

Sony V George

  • Apr 4th, 2007
 

1. How do u difine an error page?

2.What r the methods called in servlet life cycle?

3.How can u make session variables un available?

4. How to change the port no of agiven application server?

5.How do udeploye an EJB in the existing application using webspehere?

6.Why and in wat kind of requirments we need to use EJBs?



 It seems like u r new to j2ee. All those u asked only the basic stuff. Read any JSP book first
1. Create one jsp page and there is tag called IsErrorPage = True, it means this is an error page . I u need to call this error page in ur application u can decalre errorpage ="give realtive url"

2.    Init(). For intilizing the servlet.
       Service(). For servicing the request .
       Destroy(). TO destroy the resource allocated by Init().
3. In Jsp There having an attribute like Session = false.

4. Inside the appication server(jBoss) , u just go to server /default/deploy/tomacat5.5.rar/server.xml. Inside server.xml u can see Tag
<connector-port>8080</connector-port>. give some other name apart from 8080.

Restart the server and try with new port.

5.  Not used websphere.

6. EJB is mainly for distributed application. It is following the RMI concept. First u lean the RMI concept the GO for EJB so that u can easily follow it.

   In RMI we are binding the Remote name and keep in the RMiregistry. It will cause when it will use on an large application enviornment. Also we need to write all the security for transaction ,it will very hectic for the programes.

In Ejb We have a container , it will provide lot of service like 

                                                      1.persistance
                                                      2.Security
                                                      3.concurrency control.
                                                      4.Load balancing Etc
It will make our transction more powerful.

Having lot of concepts in Ejb These al are the basic stuff.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions