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

problem in jsp and action

I want to send a  parameter from a jsp page...and i want to get it in the action class.

i want to do this ...because i want to know from which page this action is called .

so, i did

session.setAttribute("pageTracker","fromManagement");  at the top of the jsp page

And in the action class i did

// do something


is this correct ?  but this seems erroneous ....i am not getting the desired result.

I cant use hidden parameter in the jsp form ...because the form is html:form ..a struts  from  .

In fact i am looking for a way so that  my action class can know from which jsp it is coming.
2 Solutions
You can try print out the value in the session see if the action able to get the value.

However, is best not to store the value in session, from what I see this is a per request action.
Not sure why you cant use hidden value in <html:form>, there's no problem using <html:hidden ..> unless the value you are storing is P&C.
cofactorAuthor Commented:
If  i  use  hidden param  ...then do  i need to  add a property for this hidden parameter  into the action from bean ?

Yes, if you use the struts form tag, it will look for the property name in form bean.
If you don't want to create the property in form bean, then use <input type="hidden"..>. This way you have to get the value from request.getParameter().
can you try this:

in your jsp:
<html:hidden name="yourFormBean" property="pagetracker" value="Coming from JSP1"/>


in your struts-config:
<form-bean name="yourFormBean" type="com.YourFormBean"></form-bean>

<action path="/whatever" type="com.YourActionForm" name="yourFormBean" scope="session">
      <forward name="go" path = "/WEB-INF/pages/YourJSP.jsp"/>            


in your YourFormBean:

private String pagetracker;

public String getPagetracker()
      return pagetracker;
public void setPagetracker(String pagetracker){
      this.pagetracker = pagetracker;


in your YourActionForm:

private String form_pagetracker = "";

public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception

YourFormBean bean = (YourFormBean) form;
form_pagetracker = request.getParameter("pagetracker");      

// Finish with                                    
return (mapping.findForward("go"));

Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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