structs中从jsp页面为啥不能跳转到action中(请哪位大侠教教小弟,急!!)

wxtking2010 2009-07-29 07:40:23
jsp页面:
<%@ page language="java" contentType="text/html; charset=GB2312"%>

<%@ include file="../common/taglibs.jsp" %>

<html:html>
<head>
<title>新建用户</title>
</head>
<body>
<html:form action="newuser.do">
<table width="60%" border="1" align="center">
<tr>
<td width="30%" align="left">用户名:</td>
<td width="70%"><input name="username" type="text" ></td>
</tr>
<tr>
<td align="left">密码:</td>
<td><input name="password" type="password" ></td>
</tr>
<tr>
<td align="left">确认密码:</td>
<td><input name="password2" type="password"></td>
</tr>
<tr>
<td align="left">性别:</td>
<td>
<input name="sex" type="radio" value="1">男
<input name="sex" type="radio" value="0" checked>女
</td>
</tr>
<tr>
<td align="left">Email:</td>
<td><input name="email" type="text"></td>
</tr>
<tr>
<td align="left">通信地址:</td>
<td><input name="address" type="text"></td>
</tr>
<tr>
<td align="left">用户等级:</td>
<td>
<input name="grade" type="radio" value="1">管理员
<input name="grade" type="radio" value="0" checked>普通用户
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="提交">
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
<form-beans>
<form-bean name="userInfoForm" type="nm.admin.form.UserInfoForm" />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="ToUserList" path="/NoticeManager/admin/userlist.jsp" />
</global-forwards>
<action-mappings >
<action path="/newuser" type="nm.admin.action.NewUserAction" name="userInfoForm" scope="request" input="/NoticeManager/common/messagepage.jsp" />
</action-mappings>
<message-resources parameter="nm.ApplicationResources_zh" />
</struts-config>

在跳转到NewUserAction中我输入 System.out.println("aaaaaaaaaaa");打不出来
地址栏:http://localhost:8082/ch12_SSH/newuser.do
页面不显示任何内容。这到底是为什么呢??请哪位大侠教教小弟,实在想不出来。谢谢
...全文
989 26 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
herov8 2011-04-20
  • 打赏
  • 举报
回复
看一下吧?
zuolin1025 2009-07-31
  • 打赏
  • 举报
回复
缺少属性
douchog_13k 2009-07-31
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 haiyanjava 的回复:]
form标签应该这样写: <html:form action="/newuser" method="POST">
[/Quote]
这样写应该没有问题,如果还是不行就在前面加上你的工程名试试如:"action="/ProjectName/newuser"
pei_zhenxi 2009-07-31
  • 打赏
  • 举报
回复
<action-mappings >
<action path="/newuser" type="nm.admin.action.NewUserAction" name="userInfoForm" scope="request" input="/NoticeManager/common/messagepage.jsp" />

<forward name="newuser" path="="/newuser" >加上试试


</action-mappings>
thqtanghequn 2009-07-29
  • 打赏
  • 举报
回复
你的action中的没有path="/newuser",action中就没有处理怎么没跳转啊
zengyanyan89 2009-07-29
  • 打赏
  • 举报
回复
在你的文本框里和单选按钮处的name里都要加上你的配制文件中的 userInfoForm
比如:
用户名:<input name="username" type="text" >
正确的是:<input name="userInfoForm.username" type="text" >

还有:<html:form action="newuser.do">
最好加上 <html:form action="<%=path%>/newuser.do">
wxtking2010 2009-07-29
  • 打赏
  • 举报
回复
非常感谢,非常激动!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
wxtking2010 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 andytom 的回复:]
这里的问题
public final class NewUserAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletRequest response)
throws Exception {
System.out.println("--->>>");
你敲错了
[/Quote]

Oh,My God。真是敲错了啊!
我真的想去撞豆腐,我写到一行里久比较长,难怪没发现呢,这样的错误在Myeclipse也没有编译错误
浪费了好几个小时,怎么找也找不出来。还是大侠厉害。佩服佩服!
tomjerrybob 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 andytom 的回复:]
这里的问题
public final class NewUserAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletRequest response)
throws Exception {
System.out.println("--->>>");
你敲错了
[/Quote]

够细致。。
wxtking2010 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 tomjerrybob 的回复:]
System.out.println("aaaaaaaaaaa");
你是说上面这句在控制台上不显示?  那说名没有执行到ACTION。

你的ACTION指定跳转页面了吗?config中没指定,是在ACTION中写的吗?

你这个现在通过全局forward能看到注册页面吗?

你的execute方法没选错吧?是HttpServletRequest/response吗?
[/Quote]

不好意思,刚才没有看到啊
ACTION指定了跳转页面 return mapping.findForward("ToUserList");
execute应该没有错,至少运行之前没有报错, 你可以看下NewUserAction.java,我已经贴出来了啊
现在NewUserAction跳转不过去
地址栏中显示:http://localhost:8082/ch12_SSH/newuser.do 页面时空白,myEclipse也没有报错啊
tomjerrybob 2009-07-29
  • 打赏
  • 举报
回复
晕,手敲得啊、
haiyanjava 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 tomjerrybob 的回复:]
标签中的 method="POST"

是默认值吧
[/Quote]

大哥:默认的是method="get"好吧
andytom 2009-07-29
  • 打赏
  • 举报
回复
这里的问题
public final class NewUserAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletRequest response)
throws Exception {
System.out.println("--->>>");
你敲错了
tomjerrybob 2009-07-29
  • 打赏
  • 举报
回复
建议写个简单的action测试下。先把页面跳转搞定,再把内容加进去。
haiyanjava 2009-07-29
  • 打赏
  • 举报
回复
不行,你那样写也是错的,我再看看还有没其它的错。
tomjerrybob 2009-07-29
  • 打赏
  • 举报
回复
标签中的 method="POST"

是默认值吧
wxtking2010 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 haiyanjava 的回复:]
form标签应该这样写: <html:form action="/newuser" method="POST">
[/Quote]

刚刚试了下,不行的啊
haiyanjava 2009-07-29
  • 打赏
  • 举报
回复
form标签应该这样写:<html:form action="/newuser" method="POST">
wxtking2010 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 andytom 的回复:]
LZ能把这几个类贴出来不
UserInfoForm.java
userlist.jsp
NewUserAction.java
messagepage.jsp
[/Quote]

UserInfoForm.java:
package nm.admin.form;

import org.apache.struts.action.ActionForm;

public class UserInfoForm extends ActionForm {
/**
*
*/
private static final long serialVersionUID = 1L;

private String username = null;

private String password = null;

private String password2 = null;

private int sex = 0;

private String email = null;

private String address = null;

private String grade = null;

public UserInfoForm() {
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getGrade() {
return grade;
}

public void setGrade(String grade) {
this.grade = grade;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getPassword2() {
return password2;
}

public void setPassword2(String password2) {
this.password2 = password2;
}

public int getSex() {
return sex;
}

public void setSex(int sex) {
this.sex = sex;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
}

userlist.jsp:
<%@ page language="java" contentType="text/html; charset=GB2312"%>

<%@ include file="../common/taglibs.jsp"%>

<html:html>
<head></head>

<body>
<%@ include file="../common/header2.jsp" %>

<html:errors/>
<%@ page import="nm.User" %>
<%@ page import="nm.Constants" %>
<%@ page import="java.util.Vector" %>
<%
Vector userVector = (Vector)session.getAttribute(Constants.USER_LIST_KEY);
User user = null;
if (userVector != null){
%>
<div align="center">
<table width="80%" border="1" align="center">
<tr align="right">
<td colspan="4">
<a href="checkpower.do?functiontype=newuser">新建用户</a>
<a href="adminlogoff.do">注销登录</a>
</td>
</tr>
<tr align="center">
<td colspan="4">用户管理</td>
</tr>
<tr align="center" bgcolor="#0099CC">
<td width="25%">用户名</td>
<td width="25%">级别</td>
<td width="25%">编辑</td>
<td width="25%">删除</td>
</tr>
<%
for(int i=0;i< userVector.size();i++){
user = (User)userVector.get(i);
%>
<tr align="center">
<td>
<%= user.getUsername() %>
</td>
<td>
<%= user.getGrade() %>
</td>
<td>
<a href="checkpower.do?functiontype=useredit&username=<%= user.getUsername() %>">编辑</a>
</td>
<td>
<a href="checkpower.do?functiontype=userdelete&username=<%=user.getUsername() %>">删除</a>
</td>
</tr>
<%
}
%>
<tr bgcolor="#0099CC">
<td colspan="4">
<form method="post" action="usersearch.do">
请输入您要搜索的用户名:
<input type="text" name="username" size="15" maxlength="50">
<input type="submit" name="Submit" value="提交">
</form>
</td>
</tr>
</table>
</div>
<%
}
else{
%>
无用户信息!
<%
}
%>
<%@ include file="../common/footer.jsp" %>
</body>
</html:html>

NewUserAction.java:
package nm.admin.action;

import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

import nm.Constants;
import nm.DB;
import nm.User;
import nm.admin.form.UserInfoForm;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

public final class NewUserAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletRequest response)throws Exception{
System.out.println("--->>>");
UserInfoForm newUserForm = (UserInfoForm) form;
String username = newUserForm.getUsername();
String password = newUserForm.getPassword();
int sex = newUserForm.getSex();
String email = newUserForm.getEmail();
String address = newUserForm.getAddress();
String grade1 = newUserForm.getGrade();
String grade = null;
if ("1".equals(grade1)){
grade = "admin";
}
else{
grade = "user";
}

ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource) context.getAttribute(Constants.DATASOURCE_KEY);
DB db = new DB(dataSource);

HttpSession session = request.getSession();
ActionMessages errors = new ActionMessages();
String pageForward = "ToErrorPage";

User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setSex(sex);
user.setEmail(email);
user.setAddress(address);
user.setGrade(grade);

if (user.insert(db)){
Vector userVector = new Vector();
userVector = User.searchUsers(db);
session.setAttribute(Constants.USER_LIST_KEY, userVector);
pageForward = "ToUserList";
}
else{
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.newuser.insert.failed"));
if (!errors.isEmpty()){
saveErrors(request, errors);
}
}

db.close();
return mapping.findForward(pageForward);
}
}

messagepage.jsp:
<%@ page language="java" contentType="text/html; charset=gb2312"%>

<%@ include file="../common/taglibs.jsp" %>
<html:html>
<head>
<title>
消息页面
</title>
</head>

<body>
<%@ include file="../common/header3.jsp" %>

<center>
<html:errors />
<h2>
<a href="javascript:history.go(-1)">返回上一页</a>
</h2>
</center>
<%@ include file="../common/footer.jsp" %>
</body>
</html:html>
andytom 2009-07-29
  • 打赏
  • 举报
回复
LZ能把这几个类贴出来不
UserInfoForm.java
userlist.jsp
NewUserAction.java
messagepage.jsp
加载更多回复(6)

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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