Win a copy of Head First Android this week in the Android forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Running servlets from with jsp

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a query which I am unable to find the answer too. I have a small web app set up using the struts framework. Within this I have a number of jsp files for content.

I also have a number of servlets used to access the database.

My question is this:
Is there a way to include a servlet in a jsp page i.e. have a jsp with all the html tags and stuff and make a call to a servlet which will then go access the database, retrieve it and then display it within the page

Or using struts and the tiles capability, can the servlet be embedded.

Hope someone can help as I've only been looking at struts and jsp/servlets for a week now so I still have a lot to learn
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, you could include the servlet with a JSP include action.

But... it's not a very standard or accepted thing to do.

If you're already working in Struts, then this is the type of thing that would normally take place in a Struts action prior to reaching the JSP page in the first place. Why are you waiting until you have forwarded to a presentation resource (the JSP) before trying to access the database?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is generally done the other way around.
The call is made to the servlet (controller).
The Servlet instanciates a bean or some beans and passes the request parameters to them.
The beans do whatever work in needed (talk to database, etc...).
The servlet then bind the beans (or results from the beans) to a particular scope (request, session, context) and forwards to the JSP (view) for handling.

What you've described can be accomplished with the <jsp:include ... /> action.


[KLUNK]
[ July 28, 2006: Message edited by: Ben Souther ]
reply
    Bookmark Topic Watch Topic
  • New Topic