在jsp struts中读取一个对象2

时间:2017-07-18 05:20:40

标签: java struts2

我正在研究struts 2,我需要使用db中的一些值来填充我的文本字段。

我能够从db中检索值但是我无法在我的jsp ussing struts2标记中获取该值。

以下是我的动作类:

package com.equant.circuit.ppd.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.equant.circuit.action.AdminAction;
import com.equant.circuit.ecms.domain.CSBReleaseDetailsBean;
import com.equant.circuit.manager.PPDManager;
import com.equant.common.util.ProxyUtils;
import com.equant.newcommon.util.CCRLogger;
import com.sun.org.apache.bcel.internal.generic.NEW;




public class CSBUploadAction extends BaseAction  {


    PPDManager managerPPD = (PPDManager) ProxyUtils.getManager(PPDManager.class);
    private static final long serialVersionUID = 1L;
    private CSBReleaseDetailsBean[] cSBReleaseDetailsBeanList;
    private HttpServletRequest request;
    private List <Specification> changeSpecificationDetailsList = new ArrayList<Specification>();
    private Specification specificationBean = new Specification();
    private String serialNo;

    private String relNo;
    public String getSerialNo() {
        return serialNo;
    }

    public void setSerialNo(String serialNo) {
        this.serialNo = serialNo;
    }

    public String getRelNo() {
        return relNo;
    }

    public void setRelNo(String relNo) {
        this.relNo = relNo;
    }

    public String getRfcNo() {
        return rfcNo;
    }

    public void setRfcNo(String rfcNo) {
        this.rfcNo = rfcNo;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getChangeNumber() {
        return changeNumber;
    }

    public void setChangeNumber(String changeNumber) {
        this.changeNumber = changeNumber;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(Date releaseDate) {
        this.releaseDate = releaseDate;
    }

    public String getRequestor() {
        return requestor;
    }

    public void setRequestor(String requestor) {
        this.requestor = requestor;
    }

    public String getDocumentLink() {
        return documentLink;
    }

    public void setDocumentLink(String documentLink) {
        this.documentLink = documentLink;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    private String rfcNo;
    private String type;
    private String changeNumber;
    private String description;
    private Date releaseDate;
    private String requestor;
    private String documentLink;
    private String status;
    private final static CCRLogger  LOGGER  = CCRLogger.getInstance(AdminAction.class.getName());


    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public List<Specification> getChangeSpecificationDetailsList() {
        return changeSpecificationDetailsList;
    }

    public void setChangeSpecificationDetailsList(
            List<Specification> changeSpecificationDetailsList) {
        this.changeSpecificationDetailsList = changeSpecificationDetailsList;
    }

/**
 * 
 * @return
 */
    public String displayCSBUpload(){
        LOGGER.info("enterin displayCSBUpload to fetch all details from CSB_RELEASE_DETAILS");

        cSBReleaseDetailsBeanList = managerPPD.getCSBReleaseDetails();
        LOGGER.info("cSBReleaseDetailsBeanList size"+cSBReleaseDetailsBeanList.length);
        for(CSBReleaseDetailsBean cSBReleaseDetailsBean : cSBReleaseDetailsBeanList){    
            Specification specification = new Specification();
            specification.setSerialNo(cSBReleaseDetailsBean.getSerialNo());
            specification.setChangeNumber(cSBReleaseDetailsBean.getRfcNo());
            specification.setDescription(cSBReleaseDetailsBean.getDescription());
            specification.setDocumentLink(cSBReleaseDetailsBean.getUrl());
            specification.setReleaseDate(new Date());
            specification.setRelNo(cSBReleaseDetailsBean.getVersionNo());
            specification.setRequestor(cSBReleaseDetailsBean.getRequestor());
            specification.setStatus(cSBReleaseDetailsBean.getStatus());
            specification.setType(cSBReleaseDetailsBean.getRfcType());
            changeSpecificationDetailsList.add(specification);
            }
        LOGGER.info("Exiting displayCSBUpload to fetch all details from CSB_RELEASE_DETAILS");
        return "success";

    }

    /**
     * 
     * @return
     */
    public String fetchTicketDetails() {
        String param = getServletRequest().getParameter("sNo");
        cSBReleaseDetailsBeanList = managerPPD.getCSBTicketDetail(param);

        for(CSBReleaseDetailsBean cSBReleaseDetailsBean : cSBReleaseDetailsBeanList){ 
            setRelNo(cSBReleaseDetailsBean.getSerialNo());
            specificationBean.setSerialNo(cSBReleaseDetailsBean.getSerialNo());
            specificationBean.setChangeNumber(cSBReleaseDetailsBean.getRfcNo());
            specificationBean.setDescription(cSBReleaseDetailsBean.getDescription());
            specificationBean.setDocumentLink(cSBReleaseDetailsBean.getUrl());
            specificationBean.setReleaseDate(new Date());
            specificationBean.setRelNo(cSBReleaseDetailsBean.getVersionNo());
            specificationBean.setRequestor(cSBReleaseDetailsBean.getRequestor());
            specificationBean.setStatus(cSBReleaseDetailsBean.getStatus());
            specificationBean.setType(cSBReleaseDetailsBean.getRfcType());

        }

        System.out.println(cSBReleaseDetailsBeanList.length+"length of list");
        System.out.println(param+"serial no");
        return "success";
    }

}

请告诉我如何使用文本字段中的struts 2标记在jsp上读取specificationBean。

1 个答案:

答案 0 :(得分:0)

下面的内容对您有用 -

<s:form action="register">

      <s:textfield name="personBean.firstName" label="First name" />
      <s:textfield  name="personBean.lastName" label="Last name" />
      <s:textfield name="personBean.email"  label ="Email"/>  
      <s:textfield name="personBean.age"  label="Age"  />

</s:form> 

<s:textfield  name = "personBean.firstName" value = "${personBean.firstName}" />

使用属性标记 -

读取值
<s:property value="personBean.firstName" />

让我知道它对你有用;)