页面提交后就没有反应,
感觉哪边都对的,请高手帮忙解决下
以下是DispatchAction的部署
<action
attribute="studentForm"
input="/addStudent.jsp"
name="studentForm"
parameter="method"
path="/admin"
scope="request"
type="com.struts.action.AdminStudentAction" />我的Action是这样写的,
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");
}
jsp如下<%@ 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>
感觉哪边都对的,请高手帮忙解决下
以下是DispatchAction的部署
<action
attribute="studentForm"
input="/addStudent.jsp"
name="studentForm"
parameter="method"
path="/admin"
scope="request"
type="com.struts.action.AdminStudentAction" />我的Action是这样写的,
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");
}
jsp如下<%@ 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>
解决方案 »
- HQL 语句—从一个查询结果集合中排除另一个集合内容
- struts提示路径错误运行不起来
- 关于spring接口实现的问题大家帮忙看看
- 在java项目下怎么整合spring和struts2,web项目下面有一个web.xml可以设置,java项目下面没有呀
- 分页查询的一个问题
- spring+hibernate+struts任务调度的问题!
- 这段代码是什么意思啊?
- myeclipse+jboss4+oracle10i_jdk1.6,报错 not support oracle driver 1.0
- 关于Hibernate注解 实体对象 主键SEQUENCE。
- filter和struts的问题?
- hibernate初始化错误,急求!
- Ext.TabPanel 中 items 不能正常显示??
或者是return new ActionForward("所有跳的文件的路径");
即可
程序有跳到addStudent方法里面执行吗?
attribute="studentForm"
input="/addStudent.jsp"
name="studentForm"
parameter="method"
path="/admin"
scope="request"
type="com.struts.action.AdminStudentAction"> <forward:name="addStudent" path="/XXX.jsp"/> --对应你的程序中的: return mapping.findForward("addStudent");
</action>
加上这个,我以前忘记加,结果死活不行,后来加了METHOD="POST"就可以了
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");
}
}
EventDispatchAction其实就是从DispatchAction 继承过来的代码这样写
public class AdminStudentAction extends EventDispatchAction{
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");
}
}配置:
<action
attribute="studentForm"
input="/addStudent.jsp"
name="studentForm"
parameter="addStudent"
path="/admin"
scope="request"
type="com.struts.action.AdminStudentAction" />
jsp里面
<html:submit property="addStudent" value="提交"/>注意:
submit的property和struts-config.xml里面parameter="addStudent"对应和action类里面方法名字对应就行点提交按钮