This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a jsp design question...

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers..
couldn't find any better subject to this post.
I've seen so many web sites URL's like this one:
www.example.com/showProduct.jsp?itemId=300
this example can be extended to other scripting languages like asp, php, perl, python, etc..
I try to design my web applications so that all the connections to the database are performed on servlets,and no jsp pages. But if I, for example, bookmark a web site like this and later on access it again it seems that all these pages are doing the connection to the database in the asp, jsp, php page itself, am I right.???
my question is:
* can I assume that these pages are doing the connection to the database in the JSP page itself?
* or... are they forwarding the request internally to the servlet and then forward it back to the jsp page?
* is this a good idea? I personally think it's bad, according to MVC.
 
LAXMI VEMARAJU
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Through jsp you will never connect to database,because they reside on client side, there won't be any security.
The db connection takes place only through servlets or ejb's, it is just your assumption that through jsp's dbconnection is happening.
Through jsp if you connect to database, then it won't be a MVC architecture.
Lakshmi
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by LAXMI VEMARAJU:
hi,
Through jsp you will never connect to database,because they reside on client side, there won't be any security.

hhmmm.. on client side?? i do not agree with you Laxmi, could you explain this please ?

The db connection takes place only through servlets or ejb's, it is just your assumption that through jsp's dbconnection is happening.

nope, you can have JSP files full of database code (including the connection itself). But you are right and I agree, this is BAD and it is not MVC architecture
So, are you saying that in this case these jsp files are forwarding the request to the servlet transparently?
thanks
 
George Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by LAXMI VEMARAJU:
hi,
Through jsp you will never connect to database,because they reside on client side, there won't be any security.
The db connection takes place only through servlets or ejb's, it is just your assumption that through jsp's dbconnection is happening.
Through jsp if you connect to database, then it won't be a MVC architecture.
Lakshmi

Hi Lakshmi,
Jsp's are also executed in server just like servlet or bean. Jsp just processes the logic and send htmls output to the client side. The security issue in case jsp or servlet are all same.
Yes Andres is correct using database connection in JSP is BAD and it is not MVC architecture.
The simplest and the most popular way is all the database connection logic is implemented in JAVA beans and the jsp simply calls the set and get method. For example the showProducts.jsp will be calling a bean say "ShoppingCart" and using the set get methods will add remove items to the bean.
Similarly in Asp also instead of JAVA Beans we have custom made DLL which will contain the Business Logic.
Thus although MVC Architecture is better, but MVC architecture is not compulsory. That is you can have all the request made to JSP page which in turn accesses the required bean and then dispalys the required output.

George Joseph
Transversal E Networks.
 
LAXMI VEMARAJU
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks George, thanks for making me right.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs ARE Servlets!
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That�s true, JSPs are just servlets that the WS compiles JIT.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic