struts DispatchAction问题

xujun7 2008-10-30 03:49:23
页面提交后就没有反应,
感觉哪边都对的,请高手帮忙解决下
以下是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>
...全文
128 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Teddy_cgs 2008-10-31
  • 打赏
  • 举报
回复
<html:form action="/admin.do?method=addStudent">

<html:form action="/admin.do?method=addStudent" method="post">
加上这个,我以前忘记加,结果死活不行,后来加了METHOD="POST"就可以了
yinweihong 2008-10-31
  • 打赏
  • 举报
回复
你的action是继承自DispatchAction,做了addStudent的method map映射吗
xujun7 2008-10-31
  • 打赏
  • 举报
回复
没有进去的
pigcoder 2008-10-31
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xujun7 的回复:]
似乎Action都没有执行,不知道怎么回事啊
[/Quote]
到底有没有进action方法呢 ?打个断点看看撒。
yinweihong 2008-10-31
  • 打赏
  • 举报
回复
用EventDispatchAction吧,这个简单点
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类里面方法名字对应就行

点提交按钮
xujun7 2008-10-31
  • 打赏
  • 举报
回复

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");
}
}
yinweihong 2008-10-31
  • 打赏
  • 举报
回复
把你这个action的代码全部贴出来看看~
xujun7 2008-10-31
  • 打赏
  • 举报
回复
addStudent的method map是指什么?我没有做
xujun7 2008-10-30
  • 打赏
  • 举报
回复
似乎Action都没有执行,不知道怎么回事啊
忙碌的布谷鸟 2008-10-30
  • 打赏
  • 举报
回复
<action
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>
yinweihong 2008-10-30
  • 打赏
  • 举报
回复
页面提交后就没有反应----〉
程序有跳到addStudent方法里面执行吗?
zx273064010 2008-10-30
  • 打赏
  • 举报
回复
学习
donotsmoking 2008-10-30
  • 打赏
  • 举报
回复
在配置文件中,加一<forward:name="addStudent" path="所有跳的文件的路径"/>
或者是return new ActionForward("所有跳的文件的路径");
即可

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧