Concurrent multiple requests hitting action classes

I have posted this issue in other forums, but i haven't got an answer that makes me satisfied.
Here is the scenario.
I have MVC architecture.
I have several action classes forwarded to one JSP page. Basically, one JSP page is shared by multiple action classes. The model built in the action class is displayed in the JSP page something like request.getAttribute(DATA_MODEL_VAR). "DATA_MODEL_VAR" is just string variable. The JSP page is very simple.
But I am just curious if there is any synchronization issue for JSP page. The JSP doesn't have isThreadSafe tag. I mean if there is any chance that the model built in A action class can be overriden by the model built in B action class if concurrent multiple requests are made to action class A and B. While I test some load testing, I found data (that doesn't even belong to a particular user) in JSP. That's why it makes me curious.
It would be great if someone can give me some info or resources.
Thank you.

I have posted this issue in other forums, but i haven't got an answer that makes me satisfied.
Here is the scenario.
I have MVC architecture.
I have several action classes forwarded to one JSP page. Basically, one JSP page is shared by multiple action classes. The model built in the action class is displayed in the JSP page something like request.getAttribute(DATA_MODEL_VAR). "DATA_MODEL_VAR" is just string variable. The JSP page is very simple.
But I am just curious if there is any synchronization issue for JSP page. The JSP doesn't have isThreadSafe tag. I mean if there is any chance that the model built in A action class can be overriden by the model built in B action class if concurrent multiple requests are made to action class A and B. While I test some load testing, I found data (that doesn't even belong to a particular user) in JSP. That's why it makes me curious.
It would be great if someone can give me some info or resources.
Thank you.

Similar Messages

  • Concurrent multiple requests to the same servlet from same client

              We are using weblogic as our web and app. server. We are using the weblogic oracle pool for database connections. We have jsp and servlets in the second tier with EJB on the third tier.
              We have a problem like this. We have set the oracle pool max size to 40. Some of our database searches takes about 30 seconds. If a user submit a request for such a search, it takes about 30 seconds to respond to the client.
              In the mean time if the user submits the same request again and again (by clicking the URL link in the HTML page continuosly for 50 times), the servlet takes each request, creates new thread for each request, and each thread uses a connection. So our pool runs out of connections and further to that, we get 'resource unavailabe exception' or 'pool connection failed' etc.
              All the users hang. Some times it recover back, but most of the times the server crashes.
              We have not set any time out for pool connection waiting time. By default weblogic keeps the threads waiting for connection indefinitely.
              So, now if somebody want to crash our site, simply they can go and hit a database search link (which takes about 30 secs) 50 to 100 times, and out site will go down.
              What is the good solution for this. I think this is a common problem which many people should have solved. One way is to find and block the user who is hitting many times.
              Any better solutions pl.?
              regards
              sathish
              

              "Cameron Purdy" <[email protected]> wrote in message
              news:[email protected]...
              > There are other ways to do the processing besides JMS, but the main idea
              is
              > this: DO NOT DO IT ON A WL EXECUTE THREAD IN YOUR WEB SERVER -- those are
              > for your HTTP requests and you don't want to use them up. You can use RMI
              > and have your RMI object spin off a thread.
              Now we're going in circles. I've heard it repeatedly argued here that you
              don't
              ever want to do anything in the server that is not within a server execute
              thread.
              My "big process" needs to run on the server, since it manipulates EJB's
              etc.,
              in the same sense that JavaBeans launched from a JSP page run in the server.
              So, I just don't understand why now it's not ok to use execute threads, when
              I'm going to be initiating a thread of control in the server anyway.
              >
              > Here's the second issue: idempotency. Make sure you pre-assign an ID to
              > the task, and have that ID accompany the task as it runs, use that ID to
              > update a shared resource (perhaps db) to show the progress of the task,
              and
              > keep that ID in the shared resource afterwards so that the task is not
              > repeated unnecessarily (refresh) and so the user's request now shows that
              > the task is complete.
              >
              My solution associates an AsynchTask to object to a session scope JavaBean.
              So, for a given session, there can be only 1 task object, etc. Will this
              work?
              Thanks,
              Jason
              > --
              >
              > Cameron Purdy
              > [email protected]
              > http://www.tangosol.com
              > WebLogic Consulting Available
              >
              >
              > "Jason Rosenberg" <[email protected]> wrote in message
              > news:[email protected]...
              > > Cameron,
              > >
              > > A few questions....
              > >
              > > Is JMS the only way to "kick off the big process". Is there a way to
              > > launch another servlet, or god forbid, another thread, etc.?
              > >
              > > I'd rather not have to use JMS right now, due to time constraints
              > > (it's another thing to have to figure out...).
              > >
              > > Is it necessary to use javascript to redirect? Can't we just use
              > > a simple meta refresh tag, which causes the same jsp to be
              > > hit repeatedly, and which will keep resending the html with
              > > the meta-refresh until the "big process" has completed?
              > >
              > > Also, if we have a jsp which uses a bean with session scope,
              > > don't we then get built in "uid" tracking? The bean instantiated
              > > will necessarily be of the current session, it seems, as long as the
              > > user keeps the same browser window open (or does resending
              > > cause a new session to be started--I didn't think so....).
              > >
              > > Can you elaborate on how the completed process information can
              > > be shared back to the session, and then returned to the browser, etc.?
              > >
              > > Jason
              > >
              > >
              > >
              > >
              > >
              > > "Cameron Purdy" <[email protected]> wrote in message
              > > news:[email protected]...
              > > > This cut & paste feature is getting handy ..
              > > >
              > > > --
              > > >
              > > > 1) The work to be done is assigned a uid or something similar to
              > prevent
              > > it
              > > > from being done twice
              > > > 2) The user presses the button which passes the uid in a hidden field
              > > (for
              > > > example)
              > > > 3) The serlvet responds by kicking off the big process with jms and
              > sends
              > > > back a page that displays a "processing..." message and uses
              javascript
              > to
              > > > redirect (with a place to click just in case javascript is turned off)
              > > > 4) The url redirected to includes the uid to identify the process for
              > > which
              > > > the result is desired
              > > > 5) When the process is completed, the information is placed in some
              > known
              > > > location (e.g. HttpSession or database) and the pending request to
              find
              > > the
              > > > result can return the result
              > > >
              > > > --
              > > >
              > > > Cameron Purdy
              > > > [email protected]
              > > > http://www.tangosol.com
              > > > WebLogic Consulting Available
              > > >
              > > >
              > > > "sathish kumar" <[email protected]> wrote in message
              > > > news:[email protected]...
              > > > >
              > > > > We are using weblogic as our web and app. server. We are using the
              > > > weblogic oracle pool for database connections. We have jsp and
              servlets
              > in
              > > > the second tier with EJB on the third tier.
              > > > >
              > > > > We have a problem like this. We have set the oracle pool max size to
              > 40.
              > > > Some of our database searches takes about 30 seconds. If a user submit
              a
              > > > request for such a search, it takes about 30 seconds to respond to the
              > > > client.
              > > > > In the mean time if the user submits the same request again and
              again
              > > (by
              > > > clicking the URL link in the HTML page continuosly for 50 times), the
              > > > servlet takes each request, creates new thread for each request, and
              > each
              > > > thread uses a connection. So our pool runs out of connections and
              > further
              > > to
              > > > that, we get 'resource unavailabe exception' or 'pool connection
              failed'
              > > > etc.
              > > > > All the users hang. Some times it recover back, but most of the
              times
              > > the
              > > > server crashes.
              > > > > We have not set any time out for pool connection waiting time. By
              > > default
              > > > weblogic keeps the threads waiting for connection indefinitely.
              > > > > So, now if somebody want to crash our site, simply they can go and
              hit
              > a
              > > > database search link (which takes about 30 secs) 50 to 100 times, and
              > out
              > > > site will go down.
              > > > > What is the good solution for this. I think this is a common problem
              > > which
              > > > many people should have solved. One way is to find and block the user
              > who
              > > is
              > > > hitting many times.
              > > > > Any better solutions pl.?
              > > > > regards
              > > > > sathish
              > > >
              > > >
              > >
              > >
              >
              >
              

  • 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.

  • Multiple request processing on action of commandLink

    Hi,
    I am working on a transaction based screen where on submit the transaction is done. On submit I have used action parameter of commandLink to perform a transaction. However I am facing a problem. Once submit is clicked, during the processing of the request, If I click Submit again, multiple transaction are done.
    I suspect this is due to action. Is if I use actionListener will this not be happened?
    Please advice.

    I have another screens which do not have this problem. They have used actionListener rather that action.
    My observation are during the processing of the request, on multiple requests made there is an additional transaction happened regardless of number of more request. I mean once you click on Submit, if you click more then 2 times, even though transaction takes place exactly 2 times.

  • How I can edit and then update multiple rows via JSP to Action Class?

    Hi All,
    I have a JSP page which allows users to edit the some properties for all Object returned by the db. They can then submit the changes to a Action Class which i.e.
    <form action="/SaveUserNames">
    <table>
    <c:forEach items='${requestScope["users"]}' var='user'>
    <tr align="center">
    <td><input type="text" name="userBean[ i ].firstname" value="..."/></td>
    <td><input type="text" name="userBean[ i ].surname" value="..."/></td>
    </tr>
    </c:forEach>
    <tr>
    <td><button type="submit">Save</button></td>
    </tr>
    </table>
    </form>
    In the ActionForm, there is a method, which would allow the Struts code to update my beans with the data the user editted:
    public UserBean getUserBean(int i) {
    return userBeanList.item(i);
    Although I am not sure how I can update the beans in the Action Class with what the user submitted.
    Can somebody help me for this point or can me suggest any design pattern to solve this points?
    Thanks
    Amit

    Fetch values for each user data and put into a Hashtable and then update.
    Userid is the key
    User related data is the bean (like firstname, lastname, age, job, etc), so you have ArrayList of user bean.

  • I need some help to develop the action class.

    my total concept is , browse a file and upload then after i want save that file in some folder in my system with same formatte (if u browse a 1.txt file then i want to save that file same c: temp/1.txt same formate )how can i do that? i know i have to develop the code in action class but what kind of code i have to develop.
    i suceed to upload the file but i dont have the idea to save that file in my system. but i dont know how can i save my file in the c:temp folder.?
    please help me.

    The authentication is something you can do with either https (secure the transport) or with WS-Security (Secure the message). You can add that with JDeveloper by using the context menu on a webservice.
    To create a webservice:
    - specify the xsd
    - create the wsdl
    - Generate a Java webservice using JDeveloper
    - implement the class to return the content of the request.
    Regards,
    Lonneke

  • Please help..How to get the values from a for loop in  Action  class

    I have alist of students say A(name, class, subjects, teacher).
    I need to display all the items in the list A into JSP,
    and then also the details of (name, class, subjects, teacher).
    in the action class,
    After getting the list of students from the database with ORM Layer(Toplink),
    I set request.setAttribute("students",listOfStudents).
    And then Iterate over the list and pass the parameter as student ID to the functions
    getClass(), getSubject(), getTeacher().
    Collection listOfStudents=getStudents();
         request.setAttribute("students",listOfStudent);
    for (Iterator itr = lisOfStudents.iterator(); itr.hasNext();)
         Collection classOfStudent=getClass(studentID);
         request.setAttribute("class",classOfStudent);
         Collection subjectOfStudent=getSubject(studentID);
         request.setAttribute("subject",subjectOfStudent);
         Collection teacherOfStudent=getTeacher(studentID);
         request.setAttribute("teacher",teacherOfStudent);
    mapping.findForward("listOfStudentDetails);
    In JSP
    <c:forEach var="stud" items="${students}">
    //display name in Name Column
    //one student may have more than one subject
         <c:forEach var="sub" items="${subject}">
         .......//display the subjects of the student
    //and repeat the same for the other details
    </c:forEach>
    The problem I am facing is
    If the last student has no subjects, no teachers
    It is displaying null for all the other students.
    I am understanding that the values are getting overwitten in the loop and the is frwede to JSP with the recentmost values for the attributes.
    What could be a possible solution so that I retrieve the values for individual students and will be able to display on JSP?
    ((Please ignore any syntax in theabove example it is just a mock up created from the real problem)

    The issue here is while you are retrieving all the details, you are consistently overwriting them in the request.setAttribute() call before you get to the JSP to display them.
    Do you actually have a class/object called Student?
    That object should have attributes for classes, subjects, teachers (all of which are lists apparently)
    public class Student{
      String name;
      List classes;
      List subjects;
      List teachers;
      // appropriate getter/setter methods
    }Then you load each student, and populate its individual lists.
    That lets you pass the list of students, each student having its own lists for display.
    Hope this helps,
    evnafets

  • Values from a jsp page are null in Action Class

    hi, i am working on an application...i have a jsp page with several inputs (type=text) and when a submit the form to to my action class all values      received are null.
    Here is a part of code:
    the jsp file: letter.jsp
    <form target="_self" action="/Test/editLetter.do" name="letterTF">
    <table>
    <tbody>
    <tr>
    <th>
    No of objects
    </th>
    <th>
    Weight
    </th>
    <th>
    Description
    </th>
    </tr>
    <tr>
    <td>
    Package
    <input name="package" id="package" type="checkbox">
    </td>
    <td>
    <input name="package_No" type="text" value="<%=currentBean.getPackageNo() %>"> <%-- from session...have to edit some date from a data base--%>
    </td>
    <td>
    <input name="package_weight" type="text" value="<%=currentBean.geWeight()%>">
    </td>
    <td>
    <input name="description" type="text" value="<%=currentBean.Description()%>"
    </td>
    </tr>
    <tr>
    ..................................................... <%-- It's a big form --%>
    </tr>
    <tr>
    <input type="submit" name="send" value="Send">
    </tr>
    </tbody>
    </table>
    </form>
    struts-config.xml:
    <form-bean
              name="letterTF"
              type="Test.LetterForm">
    </form-bean>
    <action path="/editLetter"
                   type="Test.LetterAction"
                   name="scrisoareTF"
                   input="/letter.jsp"
                   scope="request"
                   validate="false">
                   <forward name="success" path="/index_orders.jsp"/>
    </action>
    The ActionForm class:
    public class LetterForm extends ActionForm{
    private String package;
         private String package_No;
         private String package_weight;
         public void setPackage(String package){
    this.package = package
    public String getPackage(){
    return package;
    The action class:
    public class LetterAction extends Action{
    public ActionForward execute(     
                   ActionMapping mapping,
                   ActionForm form,
                   HttpServletRequest request,
                   HttpServletResponse response)
         throws Exception{
    String package;
    String package_No;
    String package_weight;
    LetterForm letterTF = (LetterForm) form;
    package = letterTF.getPackage();
    package_No = letterTF.getPackageNo()
    package_weight = letterTF.getPackageWeight();
    System.out.println("Package: "+package);//it will print Package: null
    System.out.println("Weight: "+weight);//it will print Weight: null
    System.out.println("Description "+description) //it will print Description: null
    As I observed its not making the set methods from LetterForm.java
    I am dealing with this bug for a couple of days an i didn't managed to break it. If anyone has an idea would he be so kind to share it with me.
    Thanks in advanced,
    David

    Basically your form beans are the place holders or containers for your jsp attributes. It has to be mapped in such a way that when the form is submitted the user entered values get populated on to your form bean.
    For Eg:
    JSP
    <html:form action="accountSearchResults.do">
    <html:text property="myName" size="15"/>
    //USE ONLY STRUTS TAGS IN JSP's. U CAN REFER TO
    //http://struts.apache.org/1.x/struts-taglib/tlddoc/index.html
    //THE PROPERTY NAME "myName" SHOULD BE DEFINED IN
    //YOUR FORMBEAN WITH getMyName AND setMyName
    //METHODS DEFINED
    </html:form>
    struts-config.xml
    <form-beans>
         <form-bean name="addEditAccount" type="org.apache.struts.validator.LazyValidatorForm">
              <form-property name="myName" type="java.lang.String">
              </form-property>
         </form-bean>
    </form-beans>
    <action-mappings>
         <action path="/accountSearchResults" type="com.zzz.AccountSearchResultAction" name="addEditAccount" scope="request">
              <forward name="success" path="NextPage.jsp">
              </forward>
         </action>
    </action-mappings>
    Action Class
    Since we have defined the form bean as a lazyvalidator instance you can use:
    PropertyUtils.copyProperties(targetBean, form);to fetch the values entered by the user. Try to use struts tags in your jsp's and map the properties to your form bean variables. Hope that helps.
    SirG

  • Values from a jsp page are null in an Action class

    hi, i am working on an application...i have a jsp page with several inputs (type=text) and when a submit the form to to my action class all values received are null.
    Here is a part of code:
    the jsp file: letter.jsp
    <form target="_self" action="/Test/editLetter.do" name="letterTF">
    <table>
    <tbody>
    <tr>
    <th>
    No of objects
    </th>
    <th>
    Weight
    </th>
    <th>
    Description
    </th>
    </tr>
    <tr>
    <td>
    Package
    <input name="package" id="package" type="checkbox">
    </td>
    <td>
    <input name="package_No" type="text" value="<%=currentBean.getPackageNo() %>"> <%-- from session...have to edit some date from a data base--%>
    </td>
    <td>
    <input name="package_weight" type="text" value="<%=currentBean.geWeight()%>">
    </td>
    <td>
    <input name="description" type="text" value="<%=currentBean.Description()%>"
    </td></tr>
    <tr>
    ..................................................... <%-- It's a big form --%>
    </tr>
    <tr>
    <input type="submit" name="send" value="Send">
    </tr>
    </tbody>
    </table>
    </form>
    struts-config.xml:
    <form-bean
    name="letterTF"
    type="Test.LetterForm">
    </form-bean>
    <action path="/editLetter"
    type="Test.LetterAction"
    name="scrisoareTF"
    input="/letter.jsp"
    scope="request"
    validate="false">
    <forward name="success" path="/index_orders.jsp"/>
    </action>
    The ActionForm class:
    public class LetterForm extends ActionForm{
    private String package;
    private String package_No;
    private String package_weight;
    public void setPackage(String package){
    this.package = package
    public String getPackage(){
    return package;
    The action class:
    public class LetterAction extends Action{
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception{
    String package;
    String package_No;
    String package_weight;
    LetterForm letterTF = (LetterForm) form;
    package = letterTF.getPackage();
    package_No = letterTF.getPackageNo()
    package_weight = letterTF.getPackageWeight();
    System.out.println("Package: "+package);//it will print Package: null
    System.out.println("Weight: "+weight);//it will print Weight: null
    System.out.println("Description "+description) //it will print Description: null
    As I observed its not making the set methods from LetterForm.java
    I am dealing with this bug for a couple of days an i didn't managed to break it. If anyone has an idea or a solution would he be so kind to share it with me
    Thanks in advance,
    David

    Basically your form beans are the place holders or containers for your jsp attributes. It has to be mapped in such a way that when the form is submitted the user entered values get populated on to your form bean.
    For Eg:
    JSP
    <html:form action="accountSearchResults.do">
    <html:text property="myName" size="15"/>
    //USE ONLY STRUTS TAGS IN JSP's. U CAN REFER TO
    //http://struts.apache.org/1.x/struts-taglib/tlddoc/index.html
    //THE PROPERTY NAME "myName" SHOULD BE DEFINED IN
    //YOUR FORMBEAN WITH getMyName AND setMyName
    //METHODS DEFINED
    </html:form>
    struts-config.xml
    <form-beans>
         <form-bean name="addEditAccount" type="org.apache.struts.validator.LazyValidatorForm">
              <form-property name="myName" type="java.lang.String">
              </form-property>
         </form-bean>
    </form-beans>
    <action-mappings>
         <action path="/accountSearchResults" type="com.zzz.AccountSearchResultAction" name="addEditAccount" scope="request">
              <forward name="success" path="NextPage.jsp">
              </forward>
         </action>
    </action-mappings>
    Action Class
    Since we have defined the form bean as a lazyvalidator instance you can use:
    PropertyUtils.copyProperties(targetBean, form);to fetch the values entered by the user. Try to use struts tags in your jsp's and map the properties to your form bean variables. Hope that helps.
    SirG

  • Action Class

    My doubt is regarding the Action Class, now sun realesed the JSF1.0, and still do we have to return the Action class with the invoke() method (as in your example) from the action class?? or can we write a simple method in the bean class as follows
    public String changePassword(){
    System.out.println ("Change Password Button clicked Hi Hi");
    return "changepass";
    and based on the return string we can handle the navigation right??
    Another thing, If I am create a seperate class other than the bean class to handle the Actions, how can I get the values of the bean class from my Action class?

    >
    Another thing, If I am create a seperate class other
    than the bean class to handle the Actions, how can I
    get the values of the bean class from my Action class?I'm not sure whether i understood your question rightly.
    do you mean :
    JSF code like below
    <h:inputText value="#{bean1.name}"/>
    <h:commandButton value="update" action="#{bean2.update}"/>
    in above conditions, write managed bean like below:
    bean2.java
    public String update(){
            FacesContext context = FacesContext.getCurrentInstance();
            ApplicationFactory factory = (ApplicationFactory) FactoryFinder.
                               getFactory(FactoryFinder.APPLICATION_FACTORY);
            Application application = factory.getApplication();
            ValueBinding vb = application.createValueBinding("#{bean1}");
            Bean1 b1 =  (Bean1) vb.getValue(context);
            String name = b1.getName();
            return "success";
    }but i thought this is a strange request.

  • 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.

  • How to send List from jsp to action class

    hi,
    i m fetching list from database and showing to jsp as follows:
    user can update that list i need to collect that updated list in next action class but i m not able to do that. can anybody suggest me any solution the code i m using is as follows:
    <html:form action="/myUpdate">
    <table>
    <tr>
         <td>
              <label><input type="text" property="name" name="name" value=""/></label>
         </td>
    </tr>
    <logic:iterate id="address" name="info" property="addressList" indexId="rowindex">
         <tr>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].houseno" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].roadname" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].city" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].state" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].country" />
         </td>
         </tr>
         </logic:iterate>
    <tr>
         <html:submit/>
    </tr>
    </table>
    </html:form>
    here in privious action i m settting bean object in session with name 'info'. it is fetching data and disply it correctly but when i m trying to get this updated data in myUpdate action i m not getting list element.

    --------------- MyBean.java----------------------
    package form;
    import java.util.Iterator;
    import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.log4j.Logger;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    * @author Sushant.Raut
    public class MyBean extends ActionForm {
         Logger log = Logger.getLogger(this.getClass());
         /* (non-Javadoc)
          * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
         @Override
         public void reset(ActionMapping mapping, HttpServletRequest request) {
              // TODO Auto-generated method stub
              super.reset(mapping, request);
              this.name = "";
         public String toString()
              System.out.println("name : " + this.name );
              for(Iterator<Address> iterator = addressList.iterator(); iterator.hasNext();)
                   Address address = (Address)iterator.next();
                   System.out.println("city : " + address.getCity());
              return null;
         private static final long serialVersionUID = 1L;
         private String name;
         private List<Address> addressList;
          * @return the names
         public MyBean()
              log.info("Bean Construtor is called.");
              System.out.println("MyBean:::::constructor is called.");
         public String getName() {
              log.info("Bean getName() is called");
              return name;
          * @param names the names to set
         public void setName(String name) {
              this.name = name;
              log.info("Bean setName() is called");
          * @return the address
         public List<Address> getAddressList() {
              log.info("Bean getAddressList() is called");
              return addressList;
          * @param address the address to set
         public void setAddressList(List<Address> address) {
              log.info("Bean setAddressList() is called");
              this.addressList = address;
         public Address getAddress(int index)
              log.info("Bean getAddress(int index) is called");
              while(index >= addressList.size())
                   addressList.add(new Address());
              return this.addressList.get(index);
         public void setAddress(int index, Address address)
              log.info("Bean setAddress(int index, Address address)) is called");
              this.addressList.add(index, address);
    }------------- Address.java------------
    package form;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionMapping;
    * @author Sushant.Raut
    public class Address {
         private String houseno;
         private String roadname;
         private String city;
         private String state;
         private String country;
         public Address(){}
          * @return the houseno
         public String getHouseno() {
              return houseno;
          * @param houseno the houseno to set
         public void setHouseno(String houseno) {
              this.houseno = houseno;
          * @return the roadname
         public String getRoadname() {
              return roadname;
          * @param roadname the roadname to set
         public void setRoadname(String roadname) {
              this.roadname = roadname;
          * @return the city
         public String getCity() {
              return city;
          * @param city the city to set
         public void setCity(String city) {
              this.city = city;
          * @return the state
         public String getState() {
              return state;
          * @param state the state to set
         public void setState(String state) {
              this.state = state;
          * @return the country
         public String getCountry() {
              return country;
          * @param country the country to set
         public void setCountry(String country) {
              this.country = country;
         public void reset(ActionMapping mapping, HttpServletRequest request)
              this.city = "";
              this.country = "";
              this.houseno = "";
              this.roadname = "";
              this.state = "";
    }------ MyAction.java------
    package action;
    import java.util.ArrayList;
    import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.log4j.Logger;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import form.Address;
    import form.MyBean;
    * @author Sushant.Raut
    public class MyAction extends Action {
         Logger log = Logger.getLogger(this.getClass());
         public ActionForward execute(ActionMapping mapping, ActionForm form,
                   HttpServletRequest request, HttpServletResponse response)throws Exception{
              MyBean myBean = new MyBean();
              log.info("Bean is Initialised.");
              String name = "sushant";
              Address address = new Address();
              address.setCity("city1");
              address.setCountry("India");
              address.setHouseno("1111");
              address.setRoadname("xyz Road");
              address.setState("MH");
              Address address1 = new Address();
              address1.setCity("Hyderabad");
              address1.setCountry("India");
              address1.setHouseno("2222");
              address1.setRoadname("ABC Road");
              address1.setState("AP");
              List<Address> addressSet = new ArrayList<Address>();
              addressSet.add(address);
              addressSet.add(address1);
              myBean.setName(name);
              myBean.setAddressList(addressSet);
              request.getSession().setAttribute("info", myBean);
              log.info("Bean is bound to session.");
              System.out.println("MyBean object is bound to session.");
              System.out.println(myBean);
              return mapping.findForward("success");
    }-------- show.jsp-----------
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
         <html:form action="/myUpdate">
              <table>
                   <tr>
                        <td>
                             <label><html:text property="name" name="info"/></label>
                        </td>
                   </tr>
                   <logic:iterate id="address" name="info" property="addressList" indexId="rowindex">
                        <tr>
                             <td>
                                  <html:text property="houseno" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="roadname" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="city" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="state" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="country" name="address" indexed="true"/>
                             </td>
                        </tr>
                   </logic:iterate>
                   <tr>
                        <html:submit title="Submit"/>
                   </tr>
              </table>
         </html:form>
    </body>
    </html>

  • Not able to call an Action class

    Hello Guys,
    I am trying to deploy a web application in SAP Netweaver developer studio, which is successfully
    deployed in Eclipse.
    When i try to click on Submit button in one JSP, then it's saying that
    "The requested resource does not exist" and the url is http://192.168.5.35:50000/Sample/searchTutorial.do
    The code in JSP as follows.
    <form action="/Sample/searchTutorial.do" method="post">
        <table>
         <tr>
              <td align="right">
                Search Tutorial
              </td>
              <td align="left">
                <input type="text" property="keyword" size="30" maxlength="30"/>
              </td>
         </tr> 
              <tr>
              <td align="right">
                <input type="submit" name="submit" value="submit">
              </td>
              </tr>
        </table>
      </form>
    here sample is the webpplication name. searchTutorial is the action class name, which is configured in
    struts-config.xml.
    the code in struts-config.xml is given below.
    <form-bean
                name="SearchTutorialActionForm"
                type="com.web.SearchTutorialActionForm">
             </form-bean>
    <action
                path="/searchTutorial"
                type="roseindia.net.web.SearchTutorialAction"
                name="SearchTutorialActionForm"
                scope="request"
                validate="true"
                input="/SearchTutorial.jsp">
                   <forward name="success" path="/SearchResultPage.jsp"/>
    </action>
    And the following jars r there in my /WEB-INF/lib folder.
    commons-beanutils.jar,commons-collections.jar,commons-dbcp.jar,commons-digester.jar,commons-fileupload.jar,commons-lang.jar,commons-logging.jar,
    commons-pool.jar,commons-validator.jar,struts.jar
    Can anyone help me.
    Your suggessions r valueble.
    Regards,
    Lakshmi M

    Hi Lakshmi,
    Is the application name "Sample" or "sample"? Aren't STRUTS URLs case sensitive? Also, just out of curiosity, why aren't you using Web Dynpro Java? It's based on the same MVC paradigm and comes out of the box with CE (not to mention all the bells and whistles).
    Rao

  • 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

  • No response due to long running Action classes

    Hi,
    I have a small issue in my application.
    Please help providing the solution for the following problematic scenario faced in my application.
    My project is generally a report generation project,
    arch used: our-own architecture(similar to struts)
    Server: deployed in tomcat server..
    On clicking a button from X.jsp, it triggers the action with the request = REQ1
    so in my configuration Xml file it checks for it and executes the corresponding Action classes and it should display the Presentation(Jsp)
    What happens is , the action class execution is taking more than 10 min, becaz of which i am getting blank screen.
    From the action to jsp , it is executing without any error, which i could see in the log files..
    Actions taken:
    improved the performance of the query, but cudnt reduce much time..
    session time is 180min, and connection timeout set to an hr. - No change- It seems this doesnt have to do anything with this.
    my Observance:
    I guess, as per arch, it is executing till jsp, but it seems that HttpRequest is getting timedout becaz of long running actions.
    Please help to find the cause and approach method to resolve this issue.
    Note: no issues to wait till 10min.. but need to get the values (reports) in the screeen..
    Thanks in advance.....

    It sounds like either the server or perhaps a firewall is timing out after 5 minutes or so. If you can examine the log files for each such machine in the network, you might find that one is reporting a timeout. If this is the case, you can change the timeout to something greater than 5 minutes, but this is not advisable. Other applications should rightfully timeout if they 'hang' for more than 5 minutes or so and you don't want to interfere with that. One possible solution is to look up something like 'jsp keepalive' to see how to get the JSP page to periodically send a message to the server to keep the session alive using something like AJAX. I tried this and I couldn't find anything that worked. Another thing you can do is do performance tuning to speed things up, or only fetch a small subset of data for the user at a time by filtering (example: instead of returning the entire telephone book, have the user select A to Z for last name and only return the last name that begins with that letter. Another possibility is to cache the data and read from the cache. Then, periodically, refresh the cache from the database at say, midnight every night. Those are the only ideas I have.

Maybe you are looking for