Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean that throws exceptions are not handled in JSP[solved]

 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a clarification to be made...
Assume there is a bean like this...


You can see the method moveNext() throws an exception but it is not catched/handled in JSP...I have a few book examples like the above where they throw Exceptions but not caught in JSP like



Is this how programmers normally code or there is a bad practice with the book examples..pls clarify...
[ January 04, 2006: Message edited by: Raghavan Chockalingam ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What book is that from?

These days, it's considered bad form to do any real processing in a JSP.
Best practices dictate that all non-view code be factored into Servlets or beans. Once the processing is done, context should then be forwarded to the JSP for formatting and display only.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:

These days, it's considered bad form to do any real processing in a JSP.


I quote this for emphasis.

And I'll state it more strongly: in this day and time, if you are doing processing in your JSP -- either directly with scriptlets, or indirectly through calling processing beans from the JSP -- you are doing it wrong.

With the advent of JSP 2.0 there is no longer any excuse for badly structured web applications that do not follow the controller-to-view model.

When you structure your web application correctly, a whole host of sticky and icky problems (like the one you mention) magically just go away.
[ January 03, 2006: Message edited by: Bear Bibeault ]
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The title of the book is "JSP Weekend crash course" but in "Beginning JSP" from Wrox they are catching and throwing errors for the same method....why one has to do both of them???
They have something like...
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bean and Bear, I have written bean something like this to make operations on a Forums_tbl in my database. I would make calls to this method from the JSP page...do you think I have made errors somewhere...I mean to say that I have followed any bad practice??? Please forgive places where I have not handled exceptions cos earlier I was following some book and I am going to change them now....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghavan Chockalingam:
The title of the book is "JSP Weekend crash course" but in "Beginning JSP" from Wrox they are catching and throwing errors for the same method....why one has to do both of them???
They have something like...


Sometimes you see SQLExceptions propogate outward because:
a) They should be handled by the application-defined error handlers, not the code
b) closing a connection or other resource can throw a SQLException that the author doesn't want to deal with
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are really interrested in following modern-day best practices, you should look up the terms "MVC" and "Model 2". These outline a web application structure in which all processing takes place under the control of a servlet controller prior to forwarding to a JSP page to render the view.

In that way, any issues are ususally dealt with under the control of Java code and by the time the JSP gains control, there's nothing left to do but display the data.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghavan Chockalingam:
The title of the book is "JSP Weekend crash course" but in "Beginning JSP" from Wrox
[/CODE]


It's important to look at the date on a JSP book.
Servlets have seen little change over the last five years but JSP has changed drastically.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
If you are really interrested in following modern-day best practices, you should look up the terms "MVC" and "Model 2". These outline a web application structure in which all processing takes place under the control of a servlet controller prior to forwarding to a JSP page to render the view.

In that way, any issues are ususally dealt with under the control of Java code and by the time the JSP gains control, there's nothing left to do but display the data.


In addition, you might want to look at container managed connection pooling.
Tomcat implements this with Jakarta DBCP
http://jakarta.apache.org/commons/dbcp/
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic