1
votes

I have a problem with Struts 2.

  1. Retrieve necessary data from database.
  2. Show the data in JSP
  3. In the JSP, I will do submit the form.
  4. The retrieved data doesn't exist in the JSP page.
  5. To show, I need to retrieve the data from database again.

So, I need to retrieve the data from database in every submit action of the same page. But I don't want to retrieve like it. How can I maintain the data in submit action?


JSP Page:

<s:form name="XXXXXX" action="XXXXXXXX" method="post">
<div align="right" style="width: 80%">
    <display:table name="userSearchForms" pagesize="${pageSize}" 
        cellpadding="5px;" cellspacing="5px;" requestURI=""
        class="displayTable" id="displayTable"
        style="border: 3px solid #D9D9D9; border-collapse: collapse; width: 100%;height: 100%;align: right;border: 3px solid #D9D9D9;">
        <display:column title="#" style="border:1px solid black;">
            <input type="radio" name="prep"
                onclick="selectRadio(this.form, '<s:property value="#attr.displayTable.companyId"/>','<s:property value="#attr.displayTable.userId"/>')">
        </display:column>
        <display:column title="companyName" property="companyName" value="companyName"
            style="border:1px solid black;"></display:column>
        <display:column title="departmentName" property="departmentName" value="departmentName"
            style="border:1px solid black;"></display:column>
        <display:column title="userName" property="userName" value="userName"
            style="border:1px solid black;"></display:column>
        <display:column title="email" property="email" value="email"
            style="border:1px solid black;"></display:column>
    </display:table>
</div>

<div style="margin-left: 10%; width: 80%; text-align: right;">
    <s:submit value="Register" action="OtherAction1"/> 
    <s:submit value="Update" action="OtherAction2" /> 
    <s:submit value="Delete" action="OtherAction3"/>
</div>

</s:form>

Action Class:

public class sampleAction extends ActionSupport{
private List<searchForm> userSearchForms;
public List<searchForm> getUserSearchForms() {
        if (userSearchForms == null) {
            userSearchForms = new ArrayList<searchForm>();
        }
        return userSearchForms;
    }

public void setUserSearchForms(List<searchForm> userSearchForms) {
        this.userSearchForms = userSearchForms;
    }

public String execute(){
 // Retrieve the data from database;
 // Set to the userSearchForms;
 return SUCCESS;
}

public String OtherAction1(){
  // Other Program Logic;
  return SUCCESS;
}

public String OtherAction2(){
  // Other Program Logic;
  return SUCCESS;
}

public String OtherAction3(){
  // Other Program Logic;
  return SUCCESS;
}

}

I need to retrieve data from database in OtherAction1, OtherAction2 and OtherAction3 method.

1

1 Answers

0
votes

You have to retrieve the data from the database. This is how web application works, it persist some data to unload from memory. Keeping in memory such data is expensive, because the memory itself is expensive and the server has a limited physical memory capacity. If the data is dependent from the user is browsing then unload the data becomes requirement #1 because the number of possible users concurrently working in application may vary and the memory requirement might increase.

Submit the form is a usual process of passing data entered by user to a web application. Before submit the JSP might render some data to view by the user. If the data required doesn't load means that a web application has errors and them should be resolved.

You should take it into account that using a server operating memory is expensive. If you will keep such data in session or application scope the data will hold in the operating memory. More data you save in those scopes more memory requirement needed. Keep it in mind while designing your web application.