Struts2关于struts.xml的配置问题,我又404了,新人求大神指教,感激不尽!

nichilemaworld 2015-02-02 09:44:30
login.jsp是起始界面,这个页面是没问题的,运行界面如下:
login.jsp的代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
function regist(){
myform.action="login!register.action";
myform.submit();
}
</script>
<s:form action="login!execute.action" method="post" namespace="/" name="myform">
<s:textfield name="username" label="用户名" size="15"/>
<s:password name="password" label="密码" size="15"/>
<input type="submit" value="登陆"/>
<input type="button" value="免费注册" onclick="regist()" style="display:inline;"/>
</s:form>
</body>
</html>

但是每次点击登录或者注册时就会报错,这是报错信息
目前我怀疑是struts.xml的配置问题,但不知道怎么修改,求大神指正。这是struts.xml的代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<constant name="struts.i18n.encoding" value="GBK"/>
<package name="default" extends="struts-default" namespace="/">
<action name="adduser" class="action.UnIoCAddUserAction">
<result name="success">/user_list.jsp</result>
</action>
<action name="login" class="action.LoginAction">
<result name="success">/success.jsp</result>
<result name="regist">/regist.jsp</result>
</action>
</package>
</struts>


再附上LoginAction类的代码:

package action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
private String username;
private String password;
//登陆成功要执行的方法
public String execute() throws Exception{
return SUCCESS;
}
//会员注册要执行的方法
public String register(){
return "regist";
}
//处理会员注册信息,当会员注册成功时,跳转至登陆界面
public String executeReg(){
return SUCCESS;
}

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

public String getUsername(){
return username;
}

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

public String getPassword(){
return password;
}
}


本人小白,大神有什么可直说,为学知识,什么都愿意接受
...全文
399 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
W2G 2015-03-24
  • 打赏
  • 举报
回复
你在页面先不要写login!register.action这种方式,写正常点的,然后打个断点在调试
sfgsfg1314 2015-02-04
  • 打赏
  • 举报
回复
引用 14 楼 nichilemaworld 的回复:
我又解决了,写下来给以后能看到这个帖子的人看。 我struts.xml里少设置了一个属性,我这是动态访问调用,所以要多加一句
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
这句代码的意思是设置动态调用为打开
我感觉这动态调用写的是故意卖弄,能写规范点的东西不好好写
missMeyo 2015-02-04
  • 打赏
  • 举报
回复
一开始想到楼上的答案了。
nichilemaworld 2015-02-03
  • 打赏
  • 举报
回复
我又解决了,写下来给以后能看到这个帖子的人看。 我struts.xml里少设置了一个属性,我这是动态访问调用,所以要多加一句
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
这句代码的意思是设置动态调用为打开
MRbean12 2015-02-03
  • 打赏
  • 举报
回复
web.xml没有配置对吧,看一下,字母有没有缺漏什么的
玉立琦 2015-02-03
  • 打赏
  • 举报
回复
引用 10 楼 nichilemaworld 的回复:
[quote=引用 8 楼 yuliqi0429 的回复:] 首先是web.xml配置信息,有没有问题。然后就是你的java类有问题,你的action中
public String execute() throws Exception{
        return SUCCESS;
    }
是登陆执行,但是注册执行的绝对不是
//会员注册要执行的方法
    public String register(){
        return "regist";
    }
什么意思 ??我这个是按照书上敲的,书上就这么写的[/quote] 你有没有看一下web.xml的配置,web.xml是前后交换数据的第一步。
nichilemaworld 2015-02-03
  • 打赏
  • 举报
回复
引用 7 楼 hjgzj 的回复:

public String register(){
System.out.println("-----------------------------");
return "regist";
}

现打印下进来没 然后再确定是不是返回页面路径的问题


您看这是我试的,控制台没有输出这行字符,是不是就是找不到Action
nichilemaworld 2015-02-03
  • 打赏
  • 举报
回复
引用 8 楼 yuliqi0429 的回复:
首先是web.xml配置信息,有没有问题。然后就是你的java类有问题,你的action中
public String execute() throws Exception{
        return SUCCESS;
    }
是登陆执行,但是注册执行的绝对不是
//会员注册要执行的方法
    public String register(){
        return "regist";
    }
什么意思 ??我这个是按照书上敲的,书上就这么写的
wyx100 2015-02-03
  • 打赏
  • 举报
回复
引用 8 楼 yuliqi0429 的回复:
首先是web.xml配置信息,有没有问题。然后就是你的java类有问题,你的action中
public String execute() throws Exception{
        return SUCCESS;
    }
是登陆执行,但是注册执行的绝对不是
//会员注册要执行的方法
    public String register(){
        return "regist";
    }
玉立琦 2015-02-03
  • 打赏
  • 举报
回复
首先是web.xml配置信息,有没有问题。然后就是你的java类有问题,你的action中
public String execute() throws Exception{
        return SUCCESS;
    }
是登陆执行,但是注册执行的绝对不是
//会员注册要执行的方法
    public String register(){
        return "regist";
    }
  • 打赏
  • 举报
回复

public String register(){
    System.out.println("-----------------------------");
    return "regist";
}
现打印下进来没 然后再确定是不是返回页面路径的问题
nichilemaworld 2015-02-02
  • 打赏
  • 举报
回复
引用 5 楼 sen_linzhiwang 的回复:
如果处理类中,默认处理方法就是execute,那不用在struts中配置method,如果不是,则要配置。把login.action应该就可以.一般出现404,要么就是action不对,还有就是配置的返回jsp路径有问题。
您看我这个action中有三个方法,不指定应该就不行吧,您能不能再帮我具体分析下,看看我这个是哪里错了
王者_来归 2015-02-02
  • 打赏
  • 举报
回复
如果处理类中,默认处理方法就是execute,那不用在struts中配置method,如果不是,则要配置。把login.action应该就可以.一般出现404,要么就是action不对,还有就是配置的返回jsp路径有问题。
nichilemaworld 2015-02-02
  • 打赏
  • 举报
回复
引用 2 楼 Fandy_Chen 的回复:
你是什么服务器
tomcat8
nichilemaworld 2015-02-02
  • 打赏
  • 举报
回复
引用 1 楼 qq_21525397 的回复:
错误说的是struts配置文件中没有找到对应的action 我不知道login!execute.action里的!execute是什么意思,但是我认为改成login.action就可以执行到下一步了
execute就是被调用的方法名啊,如果不写的话就没法指定要调用的方法了啊
Fandy_Chen 2015-02-02
  • 打赏
  • 举报
回复
你是什么服务器
小生--幻 2015-02-02
  • 打赏
  • 举报
回复
错误说的是struts配置文件中没有找到对应的action 我不知道login!execute.action里的!execute是什么意思,但是我认为改成login.action就可以执行到下一步了

81,092

社区成员

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

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