• 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

if("fromManagement".equals((String)session.getAttribute("pageTracker")))
{
// do something

session.removeAttribute("pageTracker");
}



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.
0
cofactor
Asked:
cofactor
2 Solutions
 
boonlengCommented:
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.
0
 
cofactorAuthor Commented:
If  i  use  hidden param  ...then do  i need to  add a property for this hidden parameter  into the action from bean ?

0
 
boonlengCommented:
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().
0
 
ayeenCommented:
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"/>            
</action>

-----------------------------------------------------------------

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");      
bean.setPagetracker(form_pagetracker);

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


-----------------------------------------------------------------
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
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