aspose file tools*
The moose likes Struts and the fly likes Invoking java layer from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Invoking java layer from JSP" Watch "Invoking java layer from JSP" New topic
Author

Invoking java layer from JSP

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I have a parent JSP, lets say JSP-1 and a small jsp (JSP-2)which will be included in JSP 1.

Whenever jsp 1 is loaded I want jsp-2 to make a call to db and fetch the latest values. The real challenge is we don't have any buttons to use. The invocation should happen on the fly.

Can we do this without having java code in the jsp page?


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

That's not really a modern structure to follow. Rather the data access would not be triggered by the JSP, but by a controller servlet invoked before the JSP.

If you are interested in structuring you web app using best practices, this article may be of some use.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Thanks for your response.

I am using Struts in my application.

This is my requirement. I have couple of columns in a table where one is a key and another is a value. I need to show those values in those pages which are mapped to the key(different pages are identified by using the key).

I thought of using a generic JSP page and control the display with logic equal tags. But my problem is how to trigger the query to fetch the values in the included JSP page.

Is there a better design to this requirement.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I am using Struts in my application.


I'm going to move this to our Struts forum.
If you're using Struts, you should try to follow Stuts best practices.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm not sure I understand what you're trying to do, but it seems like you want to allow the user to make some selection and then have part of the page redisplay with new information. If this is true, I'd recommend one of the following options:

1 - Use an IFRAME for the changeable portion of the page. Then have the user action submit the page and specify the IFRAME name as the target. The Struts Action class would then retrieve information from the database and forward to a JSP which is then displayed in the IFRAME.

2- Use AJAX to make a call to the server without submitting the page and then use JavaScript and DOM to rebuild part of the page on the fly.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoking java layer from JSP