[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

JSP Navigation + Passing values

I am a relatively newbie with JSP, JavaScript, Struts, Tiles and am having a problem passing a value between screens.

The first part of what I am doing works fine but it is the second part that I am struggling with.

[B]Part 1[/B]
I have a JSP that displays a list of users in a multi column table - it is populated via the logic:iterate tag.

I have a Javascript function that allows me to select a particular row in the table and a 'Next' button with a call to a function for URL rewriting onclick="return fnEditUser()

  function fnEditUser() {

The userEdit.do relates to a Struts ActionClass where I use request.getParameter to return the userId before using this Id to look up the database for particular information.  This information is then populated into an editable table where a users details can be edited or deleted.  I have the edit working but it is the delete that I am having problems with.

Part 2
When I press delete I need a way of retaining the userId that I passed from the first screen as I want to display a confirmation screen with some of the user details.

Do I have to write a new function to rediscover what the userId is or can I get this information from request.parameter or the Action form somehow.

If I have onclick="window.location='userDelete.do'" on the Delete button I can't query the Form or request.parameter in the following Action Class.

I hope that this is not too vague and is on the correct forum.
1 Solution
I suggest you use session scope for your form bean. This you can configure using
the action tag in your struts-config.xml.

Next, if you are using parameters, the value will be lost once you reach your action
method. To retain the value you can either have an attribute for userid in your ActionForm
itself or can set the parameter again in your action before forwarding.

By default, the scope of a form bean is "session". So assuming you have not modified your struts-config.xml to make the scope as "request", the form bean will be available on the session.

So if you are using the same form for both edit and delete, you can get the id from the ActionForm itself.

If, however, the forms are different for edit and delete Actions, you can save the id in the session once you do the database lookup. So when the user clicks on delete button, you can pick the id from the session.
CoulacAuthor Commented:
I managed to solve this by the following code --> long userId = new Long(request.getParameter("userId")).longValue();  My scope is request as this is the standard for this project.  I can move the id from via url rewriting.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now