0

我在 SearchTIN.java 类中有这段代码。我想在 jsp中显示tinname & address的值

public class SearchTIN extends ActionSupport implements ServletRequestAware{

private String tin;
private String name;    
private String address;

public String getTpTin() {
    return tin;
}
public String getTpName() {
    return name;
}
public String getTpAddress() {
    return address;
}
public void setTpTin(String tin) {
    this.tin = tin;
}
public void setTpName(String name) {
    this.name = name;
}
public void setTpAddress(String address) {
    this.address = address;
}

public String execute() throws Exception {

    Debugger.border();
    Debugger.startDebug(this.getClass().toString());

    String tax = request.getParameter("tin");

    TblTaxPaymentDAO tdao = DAOFactory.getDaoManager(TblTaxPayment.class);
    TblTaxPayment t = null;
    t = tdao.findbyTIN(tax.replace("-", ""));
    TblTaxPayment tbltaxpayment = (TblTaxPayment) t;

    try{

            Debugger.print("TIN : "+tax);
            if(tax != null) {

                tin = tbltaxpayment.getTpTin();                                     
                name = tbltaxpayment.getTpName();
                address = tbltaxpayment.getTpAddress();

                }

            return SUCCESS;

JSP:的值将在输入中,名称将在文本区域名称中,地址将在文本区域地址中。

<form action="searchTIN" name="TIN" method="post" enctype="multipart/form-data">
            <div class="TIN">
            <div>
            <label style="font-size: 17px;">TIN - Branch Code</label><br><br>           
                <input id="mask" name="tin" type="text" value="" style="margin-top: -9px; width: 170px;  float: left;"/>
            <div class="buttont" style="float: left; width: 100px; height: 30px; line-height: 30px; margin-left: 4px; margin-top: -12px;">
                <a href="javascript:document.TIN.submit();" onclick="rmAlert()">Search</a>;
            </div>      
            <br><br>
            <label style="font-size: 17px;">Registered Name</label><br><br>         
                <textarea disabled id="name" name="name" style="margin-top: -9px; width: 275px; height: 40px;"/><% %></textarea>    
            <br><br>
            <label style="font-size: 17px;">Address</label><br><br>         
                <textarea disabled id="address" name="address" style="margin-top: -9px; width: 275px; height: 40px;"/></textarea>   
            <br><br>
            </div>
4

2 回答 2

0

通过在 SearchTIN 中添加以下代码解决了我自己的问题:

request.setAttribute("tin", tin);
request.setAttribute("name", name);
request.setAttribute("address", address);
于 2013-08-10T08:22:36.250 回答
0

从您的代码看来,您正在使用Strus. 添加getters和字段后,您可以使用 标签setters访问该值。valuestack<s:property/>

用于获取一个值的属性,如果没有指定则默认到栈顶。

<%@ taglib prefix="s" uri="/struts-tags" %>

<form action="searchTIN" name="TIN" method="post" enctype="multipart/form-data">
            <div class="TIN">
            <div>
            <label style="font-size: 17px;">TIN - Branch Code</label><br><br>           
                <input id="mask" name="tin" type="text" value="<s:property value="tin"/>" style="margin-top: -9px; width: 170px;  float: left;"/>
            <div class="buttont" style="float: left; width: 100px; height: 30px; line-height: 30px; margin-left: 4px; margin-top: -12px;">
                <a href="javascript:document.TIN.submit();" onclick="rmAlert()">Search</a>;
            </div>      
            <br><br>
            <label style="font-size: 17px;">Registered Name</label><br><br>         
                <textarea disabled id="name" name="name" style="margin-top: -9px; width: 275px; height: 40px;"/><s:property value="name"/></textarea>    
            <br><br>
            <label style="font-size: 17px;">Address</label><br><br>         
                <textarea disabled id="address" name="address" style="margin-top: -9px; width: 275px; height: 40px;"/><s:property value="address"/></textarea>   
            <br><br>
            </div>
于 2013-08-10T08:32:35.110 回答