• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSP tag to use to call servlet

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I've already read bunch of tutorials about jsp and servlet and I'm already aware of not using a scriplet inside a jsp. My problem is that i'm still confuse of the different tags and I don't know yet much of the functionality of the different tags.What tag would be use if I will call a servlet inside Jsp where that servlet is just simply execute something behind the scene, ie. not returning any variable.. , for example is Connection in Database.

Thanks
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would not call the servlet from the JSP. Any preparation needed by the page would be handled in the servlet controller before the servlet forwards to the JSP.
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh I see. I thought we could just easily call and run a servlet in Jsp line with a Tag. So Sir Beau,if that's the case, what tag should I use or the preparation. Are you referring for the JavaBeans tag and setAttributes place inside servlet and forward the response to JSP?[based on BeerSelect.java :). I tried it but I guess its only applicable if your passing a variable from a servlet to JSP.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

chure abcede wrote:I thought we could just easily call and run a servlet in Jsp line with a Tag.


You actually can -- the <jsp:include> action can call any resource. It's just not considered a good practice. Common practice is to handle all data activity in the controller and to keep the JSP as "dumb" as possible.

what tag should I use or the preparation.


Again, no tag. Any data activity that needs to be performed should be done before the JSP gets invoked. Have you read this article which describes page controllers?

setAttributes place inside servlet and forward the response to JSP?


Pretty much. The controller does the data access, places the data into request scope, and the request is forwarded to the JSP which accesses the values via the EL and JSTL.

I tried it but I guess its only applicable if your passing a variable from a servlet to JSP.


What do mean by "only applicable"? This is always applicable when using accepted practices.
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What do mean by "only applicable"? This is always applicable when using accepted practices.


I mean, in the code below:BeerExpert.java

JSP-result.jsp


Im wondering if, I could revise this code and just execute a bunch of codes inside the servlet and not passing a variable.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why?

Are you not interested in following accepted best practices? Why would you want make it many times more messy than necessary, and therefore more confusing and fragile?

And, of course, you should modernize the JSP to use JSTL and EL, and not obsolete scriptlets.
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh.. I see.. there is a misunderstanding. : ) . I'm referring about the use of setAttribute, hence it is passing a variable object. Of course sir Beau, I would love to follow the best practices and also consider learning JSTL and EL. I'm still reading the tutorial you've shared to me. It's a great book maybe its just me who can't catch up easily in JSP :(.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your beef with using setAttribute()? It's the way that scoped variables are created to send data from the controller to the page.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic