Struts: how to display dynamic data without a form

Posted on 2005-03-08
Medium Priority
Last Modified: 2010-04-01
I'm a bit confused about this. I've been working with Struts for a few weeks now. I know how to work with ActionForms and Actions. But I wonder how you can display a page containing dynamic data generated using parameters in the url (with Struts). Can anyone help me here?
Question by:_manu_
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 29

Expert Comment

ID: 13484456
Using JSTL it's easy


<c:out value='${param.action}'/>

will print out: Hello

Why would you want to use parameters? The idea of having actionForms is that everything is hidden from the user and you don't need to use request parameters

Author Comment

ID: 13485411
I should have been more explicit:

I have a page ('showScores.jsp') that displays a number of results from a database. How do (result) beans become available on that page if I just call that page?

And if I add a few parameters in the url (eg country=BE) the results should be limited to records only from Belgium or something. I'm not using a form here.

Do I have to use an application bean to get the results?
LVL 29

Expert Comment

ID: 13486242
Are you asking how to call the jsp without first calling the action, then then will result in errors, as you are expecting to output action form values either by the struts tags or by jstl.

Sorry to be obtuse but what exactly does " if I just call that page" mean?

I think I know what you're trying to do but I want to make sure.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 13493674
Bloodredsun, if I go directly to the page "showScores.jsp" in my browser, I want to see some "scores" from my database. On that page there will be a combobox containing countries. If I change the item selected in the country combobox the page is "reloaded" with only results for that country.

I can see how Struts comes in when I select another country (SetCountryActionForm - SetCountryAction and return to showScores.jsp). But I don't see how I can display the result the FIRST time I load the page (results for all countries) - except by writing the logic in the jsp itself.
LVL 29

Expert Comment

ID: 13494230
The idea with struts is that you have a separation of business code, such as database access, with presentation layer; your JSP. This also means that your beans/actionForms are not available to the jsp if you try to access them directly, I often put my JSPs in the WEB-INF so that they cannot be accessed directly.

What you need to do is put in some logic in your SetCountryAction that checks whether a country is selected, if not it either goes to another page, or it forwards to the page that you want with a full resultSet from your database. If you want to access a jsp "directly", without an action, then use the ForwardAction e.g. in action-mappings element of struts-config.xml

<action path="/index" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/index.jsp" />

This sounds more like an architecture issue rather than a Struts problem.
LVL 11

Expert Comment

ID: 13522638
If you just want to display data, you should be able to do that:

Import the formClass in that jsp page and, and call getter methods for the values where you want and also put logic where you don't want someone to access some part..
LVL 29

Expert Comment

ID: 13523774
If you need to access a formbean/ActionForm via JSTL it's very easy.
It's <c:out value='${[scope].[beanName.[property]}'/>

<c:out value='${requestScope.myActionForm.firstname}'/>

and testing for the value and so prevent nullpointers

<c:if test='${not empty requestScope.myActionForm}'>
//do stuff

LVL 19

Accepted Solution

Jim Cakalic earned 400 total points
ID: 13525158

To reinforce some of the previous comments, the pattern for development in Struts is that the JSPs are only about generating the presentation, not about processing requests. For this reason you'll find that the majority of Struts development teams follow a practice of hiding JSPs behind WEB-INF so that they are not publicly visible. See

Here's an article with a great diagram that illustrates the request processing path for a Struts application:

Struts helps you build applications according to a web MVC design pattern that is referred to as Model 2 Architecture. Here's another article that may assist you in understanding the difference between what you have described wanting to do (which is Model 1 Architecture) and what Struts encourages (jump to the JSP Access Models section):

Best regards,
Jim Cakalic

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question