Values from JSP to Struts Action Class

Dear All,
Am working on a small struts project, i want to get values from JSP in the Action class, i tried with sending variables using request through URL, it works fine, any other way is there to send the values from JSP to action class. Am not having any input fields in the JSP.I have links.
Thanks,
vyrav.

I have a dispatch action for that am calling the action like this viewfiles.do?parameter=edit, and i have to send a variable ID from the same page, so am doing like this through java script, viewfiles.do?parameter=edit&id=10. Am able to get the id in the dispatch action edit, but when i start tomcat with security manager its not calling the action itself and its giving accesscontrol exception, but when i directly type viewfiles.do in URL its calling the action.
I dont know wats the problem, tomcat security manager not allowing this. Please help me.
Thanks,
vyrav.

Similar Messages

  • Passing value from JSP to Action in Struts

    Hi,
    I am populating JSP page with rows retrieved from the database and
    represented as a List of Beans in forEach loop:
    <c:forEach var="list" items="${OperationsForm.OperationsList}">
    <c:choose>
    <c:when test="${list.isCompleted =='Y'}" >
    <td width="100">Completed</td>
    <td width="100"> </td>
    </c:when>
    <c:otherwise>
    <td width="100">Pending</td>
    <td width="100"><input type="image" onclick="
    rowId=value; form.action='action.do?command=notify'"
    value="${list.OperationId}" />
    </td>
    </c:otherwise>
    </c:choose>
    </tr>
    </c:forEach>
    Have hidden field: html:hidden property="rowId" value="-1"/>
    User is clicking the button corresponding to one of the rows
    and I need to pass the value of that rowId to the Action class, so it does
    something in the database [action completed]
    Now how do I pass it , is that the right way of doing it with calling
    request.getSession().getAttribute(rowId) in the Action class ?
    As of now I am getting Javascript error "Object doesn't support this
    property or method", complaining about rowId=value;
    Using Struts 1.3
    Please help !
    TIA,
    Oleg.

    So what you are saying is that I should add rowId here:
    <input type="image" onclick="form.action='action.do?command=notify&rowId='
    ${list.OperationId}"/> , correct ?
    I am not sure that it will work, especially with Struts tag.
    I will probably try something like:
    <html:submit onclick="form.action='action.do?command=notify'" value="${list.OperationId}">
    I am relatively new to Struts, so now sure what will work or not and how to do it better. How do I catch the submitted value in the Action in either of these 2 cases, via action.getSession().getProperty("rowId") /
    action.getSession().getProperty("submit") ?
    I would probably do it as a URL rather than changing the action of the form.I will have to create a new action anyway to process that row [which is sending user e-mail regarding that row data/event].
    Is the id the only thing you have to pass in?
    Or do you need other values from the screen?Selected rowId is probably the only thing I care about, can access values from the Form in Action.
    Thank you,
    Oleg.

  • Passing value from JSP to JApplet

    Hello,
    I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
    to a JApplet,
    and the parameter passed through JSP should be displaed in the JTextArea.
    It would be kindful if any of you could help.
    Thanks
    Sanam

    hello,
    thanks for reply.
    I know how to pass parameters from html,
    I want to pass values from jsp page,
    and i dono how to do it, may be we cann pass values through url connection but i dono how.
    if anone knows plz help me in solving this.
    i hvae posted my applet code.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    <applet code = "DocApplet" width = 500 height =5000>
    </applet>
    public class DocApplet extends JApplet
         private JPanel jp;
         private Container cp;
         private JTextArea jt;
         private JToolBar tb;     
         private JScrollPane sp;
         private String annotation;
         private String url;
         private Connection con;
         private Statement stmt;
         public void init()
              jp = new JPanel();
              cp = getContentPane();
              jt = new JTextArea();
              tb = new JToolBar();
              sp = new JScrollPane(jt);
              repaint();
         public void start()
              jp.setLayout(new BorderLayout());
              jp.add(tb, BorderLayout.NORTH);
              jp.add(sp, BorderLayout.CENTER);
              jt.setBackground(Color.BLACK);
              jt.setForeground(Color.WHITE);
              setContentPane(jp);
              addButtons(tb);
              repaint();
         public void run()
              repaint();
         public void paint()
         private void addButtons(JToolBar tb)
              JButton button = null;
              button = new JButton("Save");
              button.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
              tb.add(button);
    }

  • Can we call the pure java variable into the struts action class?

    Hi Everybody,
    I have created the binary tree data structure in java,Could I use the value of the variable called value in the struts action class?,pls help me thro ur reply.I have attached the java code here.Thanks in Advance
    package com.recipes.wizard.common;
    public class BinaryTreeTest {
      public static void main(String[] args) {
        new BinaryTreeTest().run();
      static class Node {
        Node left;
        Node right;
        int value;
        public Node(int value) {
          this.value = value;
      public void run() {
        Node root = new Node(5);
        System.out.println("Binary Tree Example");
        System.out.println("Building tree with root value " + root.value);
        insert(root, 1);
        insert(root, 8);
        insert(root, 6);
        insert(root, 3);
        insert(root, 9);
      public void insert(Node node, int value) {
        if (value < node.value) {
          if (node.left != null) {
            insert(node.left, value);
          } else {
            System.out.println("  Inserted " + *value* + " to left of "
                + node.value);
            node.left = new Node(value);
        else if (value > node.value) {
          if (node.right != null) {
            insert(node.right, value);
          } else {
            System.out.println("  Inserted " + *value* + " to right of "
                + node.value);
            node.right = new Node(value);
          if(node.value==1)
               System.out.println("The value is one");
             int output=node.value;
               System.out.println(output);
    }

    Hi,
    You can change the filter with the new cost element variable,Or you can assign the value of the new variable(if of same type)to old cost element ,but for that assignment again u have to change  planning function which you don't want.
    Regards,
    Indu

  • Passing value from JSP to scriptlet

    Hi
    I am trying to find a way to pass a value from jsp to the scriptlets, i.e.
    <c:set var="testValue" value="123" />
    <%
    System.out.println(testValue);
    %>
    the above code just demonstrates what I was trying to achieve, by passing the value from the jsp into the scriptlet.
    Can someone tell me if there's an easy way to do this?
    Thank you.

    Note, using scriptlet code on your page is generally something to be avoided. 99% of what you should be doing on a JSP page can be done with EL/JSTL. If you can't do it with EL/JSTL then it probably belongs in a servlet/bean.
    I always aim for 100% scriptlet free jsp pages.
    Having said that, I can still answer your question: EL attributes are stored in the scope - page, request, session, application
    ${testValue} is equivalent to pageContext.findAttribute("testValue").
    The <c:set> tag example doesn't specify a scope, so therefore you could get it like this:
    <c:set var="testValue" value="123" />
    <%
    String testValue = (String)pageContext.getAttribute("testValue");
    System.out.println(testValue);
    %>alternatively exploit the feature of the useBean tag that creates a scriptlet variable:
    <c:set var="testValue" value="123" />
    <jsp:useBean id="testValue" type="java.lang.String"/>
    <%
    System.out.println(testValue);
    %>Note that the EL variable and the Scriptlet variable are initially pointing at the same String.
    But changing the string in scriptlet code will change the value it is pointing at, while leaving the EL variable untouched.
    If you have a List in scope, and sharing it between EL and scriptlet variables then any changes to the list would be reflected because they both point at the same List object.
    cheers,
    evnafets

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • How to log exception from a struts action class

    Hi guys,
    I am recoding my application to use the strut framework. There's one small thing i wonder is that how i can log an exception arrise in an action class. In my original servlet, wherever an exception arise, i use:
    catch(Exception e)
             getServletContext().log("User enter an invalid date");
             throw e;
          }However, when i move this servlet into a action class, the getServletContext method doesnt work anymore. I thought action is a child of httpServlet but since getServletContext is not available in action, then how can i log the error?
    Hope to get some help
    Message was edited by:
    lnthai2002

    Hi guys,
    I am recoding my application to use the strut
    framework. There's one small thing i wonder is that
    how i can log an exception arrise in an action class.
    In my original servlet, wherever an exception arise,
    i use:
    catch(Exception e)
    getServletContext().log("User enter an invalid
    valid date");
             throw e;
          }However, when i move this servlet into a action
    class, the getServletContext method doesnt work
    anymore. I thought action is a child of httpServlet
    but since getServletContext is not available in
    action, then how can i log the error?
    Hope to get some help
    Message was edited by:
    lnthai2002Action class is just a POJO and works a handler of your request. ActionServlet invoke your Action class based on the action you call in your URL. When you are usign the Struts why do you need your Original Servel, use the ActionServlet and if required you can extend it and create your own servlet

  • Getting values from jsp in portlet

    Hi,
    I want to know if I submit values from a jsp page how can get those values in the portlet class (extends Generic portlet). I have tried accessing using actionRequest.getParameter() and also renderRequest.getParameter(). But I get null value .
    Do I need to add the below shown line also to the jsp -
    <portlet:defineObjects/>
    I am working with JSR 168 portlet. I am posting part of the jsp down let me know how can I go about this problem.
    <%@ page language="java"%>
    <form name="userForm" method="post">
    <table>
    <tr>
         <td>User Name</td>
         <td>
              <input type="text" name="userName"/>
         </td>
    </tr>
    <tr>
         <td>
              <input type="submit" label="Save"/>
         </td>
    </tr>
    </table>
    </form>
    Thanks

    Hi ,
    I created a sample portlet the way it is in notepad portlet and it worked fine for me . But the main difficulty is I am trying to convert an existing code and there the form submission happens in java script .The following code is used to submit the form and there I am not able to get the values in processAction().
    Please check the java script code and let me know if I can change it in someway which can make the submitted values available in the processAction().
    document.forms[0].action ='<portlet:actionURL><portlet:param name="mode" value="dummyVal"/></portlet:actionURL>';
    document.forms[0].submit();
    Thanks..

  • Accessing JSTL values from JSP

    I've run into a problem I'm not sure has a solution. Could be bad design on my part, or just a poor imagination. If this has been answered previously, please point me to the post.
    I am using some JSTL to do a SQL query and displaying the records in a select box:
    <sql:query var="aResults" sql="select * from TYPE_STATE_LIST where tslAllowable=1" />                           
    <c:forEach var="oRecord" items="${aResults.rows}">                               
      <option value="<c:out value="${oRecord.tslID}" />"><c:out value="${oRecord.tslFullName}" /></option>                                   
    </c:forEach>I want to be able to reset their selection to the value they entered when the form is refreshed, though. I'm trying to figure out how to grab the oRecord value from the JSTL and use it in a JSP IF statement:
    <% if( oRecord.tslID==request.getParameter("state") ) { %>
      <option selected value="<c:out value="${oRecord.tslID}" />"><c:out value="${oRecord.tslFullName}" /></option> 
    <% } else { %>
      <option value="<c:out value="${oRecord.tslID}" />"><c:out value="${oRecord.tslFullName}" /></option> 
    <% } %>I thought about using the JSTL <c:choose> tag instead, but then how would I access the previous value with request.getParameter()?
    Any suggestions?

    ${param.state}It's better if you place the sql query into a class rather than display it in the jsp, it's more flexible and programmable.

  • I want to send a value from JSP file to another JSP file without..

    I want to send a value from one.JSP file to another two.JSP file without to show the content HTML of the one.JSP in two.JSP (with include), only take the values processed in a Bean :
    ===================
    Bean
    package pck;
    import java.io.*;
    public class yyyy {
         public String getXxx() {    
              return cccc;
    ========================
    one.JSP
    <jsp:useBean id="idBean" class="pck.yyyy" scope="??"/>
    <%idBean.setXxx(ccc);%>
    ========================
    two.JSP
    <%@ include file="one.jsp"%>
    <%=idBean.getXxx()%>
    but without to show the content HTML of one.JSP in two.JSP.
    Can someone help me?, please.

    Why don't just put the common code in a separate file and include it in both. i.e. the code that is in one.jsp that is needed by two.jsp could be put in a common file and included in both pages, thus the HTML is separated off. If this will not work, set a boolean value in two.jsp that can be used by one.jsp to decide if the HTML should be displayed or not.
    Steve

  • Can't retrieve bean value from jsp!

    Here's the chain of events for my web app:
    JSP form (get info from user) -> forwarding jsp (uses bean to save info submitted to form)-> servlet (retrieves info from DB) -> JSP (presents DB info to user by populating values in text fields from original form)
    Right now, I can access all the values submitted to the first JSP from my servlet. However, after my servlet retrieves the info from a db and stores it in a bean and forwards the request (using requestdispatcher) to the 2nd JSP, I can't get the values from the bean from the 2nd jsp. I was able to use the bean to store the information submitted to the original JSP, however.
    Here's some relevant code:
    FROM FORWARDING JSP (which saves user-submitted info in bean)
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="request"/>
    <jsp:setProperty name="fxFormBean" property="*" />
    <jsp:forward page="/FxMatcher" />
    FROM LAST JSP (which should populate form fields)
    header stuff:
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="session"/>
    info retrieval:
    <INPUT TYPE="text" NAME="fx_key" value="<%= fxFormBean.getFx_key() %>">
    I wrote this JSP based on the example given here: http://www.jsptut.com/Editing.jsp, but I'm not getting the value from the bean. The result JSP just has value="".
    I'm pretty sure that my servlet is saving the info to bean correctly, but here's the code anyways:
    //retrieves info from DB
    FxFormBean fx = (FxFormBean) request.getAttribute("fxFormBean");
    fx.setFx_key (traderKey);
    fx.setAa_block(agent_block);
    fx.setAddition_to (additional_to);
    log("trader key: [" + fx.getFx_key() + "]"); //debugging code
    My debugging code did print out the correct info, so I don't think there's anything wrong with the bean or the servlet.
    I would appreciate any help. Thank you very much.

    The first JSP puts the bean in the request, the servlet retrieves the bean from the request and updates it but in the second JSP you set the scope to session:
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="session"/>
    So the second JSP is looking in the wrong place for your bean. Change the scope in the second JSP to request:
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="request"/>

  • Using static Delegates within Struts' Action classes

    HI,
    I have a struts app. I also have several delegate classes that connect to ejbs (session beans) used within my action classes. I was thinking about putting the delegates into a helper class as static properties. That way my action classes can just reference the same delegate. I don't want to have to create a new instance of a delegate with every request an action class handles.
    However, I'm wondering if this will cause synchronization issues with multiple requests being handle, as our site handles a heavy load of requests. Any suggestions would be appreciated?

    static will work - but IMO here's a better option
    1. Have multiple delegates (one per module - one for login, another for business process1, another for business process2)
    Advantages : Cleaner segregation, easier maintenance and readability.
    2. Maintain the business delegates as individual classes and access them through instance variables from action.
    Advantages : All the advantages of inheritance, one business process may be the child of another - for example you can have a BasePaymentDelegate and then a specific CreditCardPaymentDelegate extending it. Similarly a PaypalDelegate may also extend BasePaymentDelegate and then common functionality can be moved to the Base class.
    3. Cache the delegate instance variables in your action - so you dont have to create one per invocation. Having said that, all the business delegate methods should be stateless - all the data to a business method should be passed as local params.
    Advantages : Local variables are thread safe as long as the object itself are thread safe. So no synchronization issues.
    Hope that helps some
    Ram.

  • Two jsp forms - same action class

    Hi, I'm new to Struts/JSP so please help:
    1. I have 2 JSP forms, can they share the same action class?
    In JSP form 1, I've specified the form action class
    <html:form action="groups" >
    In JSP form 2, it's
    <html:form action="groupusers">
    In my Struts-Config.xml, I've specified for form1
    <form-bean name="GroupForm" type="org.apache.struts.validator.DynaValidatorForm">
    <action path="/groups" type="...groups.action.GroupsAction" name="GroupForm" scope="request" validate="false" parameter="methodToCall" input="/groupsframe.jsp">
    and for form2
    <form-bean name="GroupUsersForm" type="org.apache.struts.validator.DynaValidatorForm">
    <action path="/groupusers" type="...groups.action.GroupsAction" name="GroupUsersForm" scope="request" validate="false" parameter="methodToCall" input="/addGroupUsers.jsp">
    Form 1 was invoked as a child window and "getGroup" action in GroupsAction class is called.
    When a button on Form 1 is clicked, I've used javascript to invoke Form2 as a child window and call "getGroupUsers" action in GroupsAction class. Form 2 is displayed, but the "getGroupUsers" action in GroupsAction class was never called.
    Is it possible to have 2 JSP forms sharing the same action class? If so, what am I doing wrong here?
    thanks in advance for your help.

    Hi All,
    I need some clarity on the page attribute in struts validations.
    I have a page with 3 buttons. First 3 input fields and one button (first button)will be displayed in the jsp page,if i click the first button then another 3 fields and one button(second button) will be added to that jsp page , again i click the second button another 3 buttons and one butoon (third button) will be added to the jsp page.now my Problem is : can i witre all fields validation in validation.xml.if i can write all field validations , it will check the first 3 fields only, pls solve my problem

  • Displaying values from JSP in textbox

    I want to fetching values from database table using JSP and display the values in a textbox in a textbox. I found if the value is a single word, it can display correctly. but if the values are multiply words, there are just the first word appeared in the textbox. for example, I want to fetche address: 5 East 98th Street, just 5 appeared in textbox. The code is as follows:
    key = request.getParameter("key");
    person = homePerson.findByPrimaryKey(key);
    <input type="text" name="Address" value= <%= person.getAddress() %>>
    Can someone suggest on this problem. Thanks in advance.
    Qiang

    <input type="text" name="Address" value= <%=
    person.getAddress() %>>do this
    value="<%=person.getAddress()%>"
    dont forget the code... as in html spaces are ignored in values if they are not in codes.

  • How to pass the value from JSP or HTML  to Applet

    Plz reply ....How can we pass the value from the JSP Page or from HTML page to Applet embedded in same page....

    Hi,
    <applet codebase = "."
    archive = foo.jar"
    code = "com.bar"
    name = "bar"
    id = "bar"
    width = "<%=Request["width"] %>"
    HEIGHT = "<%=Request["appHeight"] %>"
    hspace = "0"
    vspace = "0"
    align = "middle"
    alt     = "Applet is Loading..."
    >
         <param name="LANGUAGE"                value="<%=Request["lan"] %>">          
         <param name="LOGOUT_USER_URL"           value="EndSession.asp">
         <param name="DATA_READ_INTERVAL"      value="10000">
         <param name="REFRESH_INTERVAL"           value="5000">     
         <param name="DEFAULT_FONT"           value="Arial">
    </applet>
    pass values @ ur html or jsp page to Applet as parameters.
    Refer above code. By using getParameter() method of Applet, u can take values inside applet.

Maybe you are looking for