67,538
社区成员
发帖
与我相关
我的任务
分享<action
attribute="studentForm"
input="/addStudent.jsp"
name="studentForm"
parameter="method"
path="/admin"
scope="request"
type="com.struts.action.AdminStudentAction" />public ActionForward addStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;
Student student = new Student();
StudentService service = new StudentServiceImpl();
try{
student.setName(studentForm.getName());
student.setLoginName(studentForm.getLoginName());
student.setPassword(studentForm.getLoginPwd());
student.setSex(studentForm.getSex());
student.setSchool(studentForm.getSchool());
student.setPhone(studentForm.getPhone());
student.setEmail(studentForm.getEmail());
service.addStudent(student);
}catch(Exception ex){
ex.printStackTrace();
}
return mapping.findForward("addStudent");
}
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<html>
<head>
<title>后台管理</title>
<link href="CSS/stylesheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: lightgrey;
}
-->
</style>
</head>
<body>
<html:form action="/admin.do?method=addStudent">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr height="40">
<td colspan="2" class="itemTitle" align="center">增加学生</td>
</tr>
<tr height="30">
<td width="160" align="right">学生姓名:</td>
<td><html:text property="name" size="41" styleClass="textBox"/></td>
</tr>
<tr height="30">
<td valign="top" align="right">登录名:</td>
<td><html:text property="loginName" size="41" styleClass="textBox"/></td>
</tr>
<tr height="30">
<td valign="top" align="right">登录密码:</td>
<td><html:text property="loginPwd" size="41" styleClass="textBox"/></td>
</tr>
<tr height="30">
<td valign="top" align="right">所属学院:</td>
<td><html:text property="school" size="41" styleClass="textBox"/></td>
</tr>
<tr height="30">
<td colspan="2" align="center">
<html:reset>重置</html:reset>
<html:submit>提交</html:submit>
</td>
</tr>
</table>
</html:form>
</body>
</html>
public class AdminStudentAction extends DispatchAction {
public ActionForward addStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;
Student student = new Student();
StudentService service = new StudentServiceImpl();
try{
student.setName(studentForm.getName());
student.setLoginName(studentForm.getLoginName());
student.setPassword(studentForm.getLoginPwd());
student.setSex(studentForm.getSex());
student.setSchool(studentForm.getSchool());
student.setPhone(studentForm.getPhone());
student.setEmail(studentForm.getEmail());
service.addStudent(student);
}catch(Exception ex){
ex.printStackTrace();
}
return mapping.findForward("addStudent");
}
}