gpt4 book ai didi

java - 获取在 jsp 上输入的值到 Action 类

转载 作者:行者123 更新时间:2023-11-30 11:39:54 25 4
gpt4 key购买 nike

当我在 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>

            <input type="submit"  id="submit" value="Submit"   title="Submit" name="Submit"   >

            </html:form>
</body>

Action 类:

    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);

}


}
}

最佳答案

这怎么行步骤1... 在 Action 类中写消息.. 例子--
request.setAttribute("消息", "用户删除成功");

第二步... 在jsp页面中获取消息.. 例子 - <%= request.getAttribute("消息") %>

你在找这个吗

关于java - 获取在 jsp 上输入的值到 Action 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13003147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com