problem in jsp and action

Posted on 2007-07-30
Last Modified: 2012-05-05
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.
Question by:cofactor
    LVL 14

    Expert Comment

    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.

    Author Comment

    If  i  use  hidden param  ...then do  i need to  add a property for this hidden parameter  into the action from bean ?

    LVL 14

    Accepted Solution

    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().
    LVL 1

    Assisted Solution

    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"));

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now