Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将jsp上输入的值获取到action类_Java_Jsp_Input_Struts_Action - Fatal编程技术网

Java 将jsp上输入的值获取到action类

Java 将jsp上输入的值获取到action类,java,jsp,input,struts,action,Java,Jsp,Input,Struts,Action,当我在jsp中键入新内容,然后将列表提交给actionclass时,如何获取该值?目前,我可以从jsp提交到action类,并查看我在action中创建的新列表。但是我希望能够重新保存我在jsp中键入的值 员工对象类: public class Employee { String empid; String empname; public String getEmpid() { return empid; }

当我在jsp中键入新内容,然后将列表提交给actionclass时,如何获取该值?目前,我可以从jsp提交到action类,并查看我在action中创建的新列表。但是我希望能够重新保存我在jsp中键入的值

员工对象类:

public class Employee {
    String empid;
    String empname;

        public String getEmpid() {
            return empid;
        }

        public void setEmpid(String empid) {
            this.empid = empid;
        }

        public String getEmpname() {
            return empname;
        }

        public void setEmpname(String empname) {
            this.empname = empname;
        }

        public Employee(String empid, String empname) {
            this.empid = empid;
            this.empname = empname;
        }



    } 
员工JSP:

<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-    8859-1"%>
    <%@ include file="../imports.jsp" %>  
     @page import="java.util.List"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title> Struts Logic Iterate Tag</title>
</head>
<body bgcolor="#ffcc66">
<html:form action="/logiciterate" styleId="LogicIterateForm" method="post"> 

    <h1>Struts logic:iterate tag </h1>
      <table style="font-weight:bold">
        <tr><td>Employee ID</td>
        <td>Employee Name</td></tr>


    <logic:iterate name="LogicIterateForm" property="emp" id="employee">
            <tr>
                    <td><html:text name="employee" value="${employee.empid}"          property="empid"
                            indexed="true" /></td>
                    <td><html:text name="employee" value="${employee.empname}"
                            property="empname" indexed="true" /></td>
            </tr>
    </logic:iterate>

@page import=“java.util.List”%>
Struts逻辑迭代标记
Struts逻辑:迭代标记
员工ID
员工姓名



行动类:

    public class LogicIterateAction extends org.apache.struts.action.Action {

private final static String SUCCESS = "success";


public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

   if(request.getParameter("Submit") == null) {          

                                LogicIterateForm formBean=(LogicIterateForm)form;
                               ArrayList<Employee> list = new ArrayList<Employee>();
                                list.add(new Employee("11A0","Jack"));
                                list.add(new Employee("11A1","Sam"));
                                list.add(new Employee("11A2","Joe"));
                                list.add(new Employee("11A3","John"));
                                formBean.setEmp(list);
                                    return mapping.findForward(SUCCESS);

}



else{

     LogicIterateForm formBean=(LogicIterateForm)form;
      ArrayList<Employee> list2 = new ArrayList<Employee>();
                list2.add(new Employee("673","Queenie"));
                list2.add(new Employee("123","Wally"));
                list2.add(new Employee("345","Spike"));
                list2.add(new Employee("564","Red"));
                formBean.setEmp(list2);



     return mapping.findForward(SUCCESS);

}


}
}
公共类LogicIterateAction扩展org.apache.struts.action.action{
私有最终静态字符串SUCCESS=“SUCCESS”;
公共ActionForward执行(ActionMapping映射、ActionForm表单、,
HttpServletRequest请求,HttpServletResponse响应)
抛出异常{
if(request.getParameter(“Submit”)==null){
LogicIterateForm formBean=(LogicIterateForm)表单;
ArrayList=新建ArrayList();
添加(新员工(“11A0”、“杰克”);
添加(新员工(“11A1”、“Sam”);
添加(新员工(“11A2”、“Joe”);
添加(新员工(“11A3”、“John”);
setEmp(列表);
返回映射。findForward(成功);
}
否则{
LogicIterateForm formBean=(LogicIterateForm)表单;
ArrayList list2=新的ArrayList();
清单2.添加(新员工(“673”、“Queenie”);
清单2.添加(新员工(“123”、“沃利”);
列表2.添加(新员工(“345”、“Spike”);
列表2.添加(新员工(“564”,“红色”));
setEmp(列表2);
返回映射。findForward(成功);
}
}
}
这是怎么回事 第一步。。。 在action类中编写消息。。 示例--
request.setAttribute(“消息”,“用户删除成功”)

第二步。。。 正在jsp页面中获取消息。。 范例--

如果您正在搜索此

请使用下面的示例

在JSP中:

<logic:iterate name="monthlyGainLossForm" property="ptcList" id="productTaxCat">
    <html:hidden name="productTaxCat" property="ptcId" indexed="true" />
    <html:hidden name="productTaxCat" property="ptcName" indexed="true" />
    <html:hidden name="productTaxCat" property="ptcActive" indexed="true" />
    <mf:tr>
        <mf:td><bean:write name="productTaxCat" property="ptcName"/></mf:td>
        <mf:td><bean:write name="productTaxCat" property="ptcActive"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="msaPtcLtcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="msaPtcLtcGLAmt" styleClass="label" style="width:100px;vertical-align:middle;" disabled="true" indexed="true"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="msaMthlyStcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="msaMthlyStcGLAmt" disabled="true" styleClass="label" style="width:100px;vertical-align:middle;" indexed="true"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="nonMsaPtcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="nonMsaPtcGLAmt" disabled="true" styleClass="label" style="width:100px;vertical-align:middle;" indexed="true"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="nonMsaStcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="nonMsaStcGLAmt" disabled="true" styleClass="label" style="width:100px;vertical-align:middle;" indexed="true"/></mf:td>
    </mf:tr>
</logic:iterate>

在行动中:

for(int m = 0; m < monthGainLossForm.getPtcList().size(); m++) {
    ProductTaxCat prodTaxCat = (ProductTaxCat)monthGainLossForm.getPtcList().get(m);

    if(prodTaxCat.getMsaMthlyStcGLType()) {
        selectedPtcTypeCounter++;
    }

    if(prodTaxCat.getMsaPtcLtcGLType()) {
        selectedPtcTypeCounter++;
    }

    if(prodTaxCat.getNonMsaPtcGLType()) {
        selectedPtcTypeCounter++;
    }

    if(prodTaxCat.getNonMsaStcGLType()) {
        selectedPtcTypeCounter++;
    }
}
for(int m=0;m
no,当我在jsp中键入bob、sally、sue等时,我希望将这些值返回到action类,以便在重新加载页面时提交时,我看到我在jsp上输入的内容,而不是默认值Show abt为bean创建对象并获取这些值
<logic:iterate name="monthlyGainLossForm" property="ptcList" id="productTaxCat">
    <html:hidden name="productTaxCat" property="ptcId" indexed="true" />
    <html:hidden name="productTaxCat" property="ptcName" indexed="true" />
    <html:hidden name="productTaxCat" property="ptcActive" indexed="true" />
    <mf:tr>
        <mf:td><bean:write name="productTaxCat" property="ptcName"/></mf:td>
        <mf:td><bean:write name="productTaxCat" property="ptcActive"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="msaPtcLtcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="msaPtcLtcGLAmt" styleClass="label" style="width:100px;vertical-align:middle;" disabled="true" indexed="true"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="msaMthlyStcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="msaMthlyStcGLAmt" disabled="true" styleClass="label" style="width:100px;vertical-align:middle;" indexed="true"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="nonMsaPtcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="nonMsaPtcGLAmt" disabled="true" styleClass="label" style="width:100px;vertical-align:middle;" indexed="true"/></mf:td>
        <mf:td><html:checkbox name="productTaxCat" property="nonMsaStcGLType" styleClass="input" indexed="true"/></mf:td>
        <mf:td><html:text name="productTaxCat" property="nonMsaStcGLAmt" disabled="true" styleClass="label" style="width:100px;vertical-align:middle;" indexed="true"/></mf:td>
    </mf:tr>
</logic:iterate>
for(int m = 0; m < monthGainLossForm.getPtcList().size(); m++) {
    ProductTaxCat prodTaxCat = (ProductTaxCat)monthGainLossForm.getPtcList().get(m);

    if(prodTaxCat.getMsaMthlyStcGLType()) {
        selectedPtcTypeCounter++;
    }

    if(prodTaxCat.getMsaPtcLtcGLType()) {
        selectedPtcTypeCounter++;
    }

    if(prodTaxCat.getNonMsaPtcGLType()) {
        selectedPtcTypeCounter++;
    }

    if(prodTaxCat.getNonMsaStcGLType()) {
        selectedPtcTypeCounter++;
    }
}