本文介绍了在JSP中显示内容时如何检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中遇到问题

<s:form action="updateBankInfo.action" enctype="multipart/form-data" method="post"      theme="simple">
  <s:actionerror />
  <div style="font-family:Times New Roman;font-size:30px; padding-left: 250px;">Bank Info</div>


  <div>
    <div class="label"><s:text name="Payee Name*   :"/></div>
    <div class="input"><s:textfield  value="%{#session.payeeName}" name="bean.payeeName" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.payeeName"/></div>
  </div>

  <div>
    <div class="label"><s:text name="Bank*   :"/></div>
    <div class="input"><s:textfield value="%{#session.bankName}" name="bean.bankName" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.bankName"/></div>
  </div>

  <div>
    <div class="label"><s:text name="Branch*   :"/></div>
    <div class="input"><s:textfield  value="%{#session.bankBranch}" name="bean.bankBranch" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.bankBranch"/></div>
  </div>

  <div>
    <div class="label"><s:text name="City*   :"/></div>
    <div class="input"><s:textfield  value="%{#session.city}" name="bean.city" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.city"/></div>
  </div>

  <div>
    <div class="label"><s:text name="A/C No*:"/></div>
    <div class="input"><s:textfield  value="%{#session.accountNo}" name="bean.accountNo" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.accountNo"/></div>
  </div>

  <div>
    <div class="label"><s:text name="IFSC Code   :"/></div>
    <div class="input"><s:textfield  value="%{#session.IFSCCode}" name="bean.IFSECode" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.IFSECode"/></div>
  </div>
  <button type="submit" style="width:107px;height:34px;margin-top:100px;margin-left:10px;font-size:1.67em;background-color:#d9d9d9;clear: left;" onclick="form.submit()"><s:text name="Update"/></button>
</s:form>

在此,我将从数据库中获取所有值并将其存储在会话中.第一次bankName将不包含任何值,并且我已使用验证器方法进行验证,因此如果我给bankname提供值并单击Submit.由于给出了value="%{#session.bankName}",因此我无法保留bankName的值,因为bankName不包含任何值.如何获取值?

解决方案

创建bean实例和getter/setter,即

private Bean bean = new Bean();
public Bean getBean() { return bean; }
public void setBean(Bean bean){ this.bean = bean; }

要保留值,您应该

Map session = ActionContext.getContext().getSession();
session.put("bankName", bean.getBankName());
// the same put for the others.

请参见简单示例. >

I am facing problem in below code

<s:form action="updateBankInfo.action" enctype="multipart/form-data" method="post"      theme="simple">
  <s:actionerror />
  <div style="font-family:Times New Roman;font-size:30px; padding-left: 250px;">Bank Info</div>


  <div>
    <div class="label"><s:text name="Payee Name*   :"/></div>
    <div class="input"><s:textfield  value="%{#session.payeeName}" name="bean.payeeName" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.payeeName"/></div>
  </div>

  <div>
    <div class="label"><s:text name="Bank*   :"/></div>
    <div class="input"><s:textfield value="%{#session.bankName}" name="bean.bankName" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.bankName"/></div>
  </div>

  <div>
    <div class="label"><s:text name="Branch*   :"/></div>
    <div class="input"><s:textfield  value="%{#session.bankBranch}" name="bean.bankBranch" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.bankBranch"/></div>
  </div>

  <div>
    <div class="label"><s:text name="City*   :"/></div>
    <div class="input"><s:textfield  value="%{#session.city}" name="bean.city" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.city"/></div>
  </div>

  <div>
    <div class="label"><s:text name="A/C No*:"/></div>
    <div class="input"><s:textfield  value="%{#session.accountNo}" name="bean.accountNo" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.accountNo"/></div>
  </div>

  <div>
    <div class="label"><s:text name="IFSC Code   :"/></div>
    <div class="input"><s:textfield  value="%{#session.IFSCCode}" name="bean.IFSECode" readonly="false" /></div>
    <div><s:fielderror fieldName="bean.IFSECode"/></div>
  </div>
  <button type="submit" style="width:107px;height:34px;margin-top:100px;margin-left:10px;font-size:1.67em;background-color:#d9d9d9;clear: left;" onclick="form.submit()"><s:text name="Update"/></button>
</s:form>

In this all the values I am fetching from database and storing in sessions. For the first time bankName will not be containing any values, and I have used validator method to do validation, so if I give value for bankname and click on submit. I am not able to retain the bankName value since I have given value="%{#session.bankName}", since bankName does not contain any value. How to retrieve the value?

解决方案

Create the bean instance and getter/setter, i.e.

private Bean bean = new Bean();
public Bean getBean() { return bean; }
public void setBean(Bean bean){ this.bean = bean; }

To retain the values you should

Map session = ActionContext.getContext().getSession();
session.put("bankName", bean.getBankName());
// the same put for the others.

See the use of session in the simple example.

这篇关于在JSP中显示内容时如何检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 04:01