struts2.5 测试action老是404,大神救救我。。

故宫遥望 2019-01-24 09:06:38
http://127.0.0.1:8080/juicy/LoginAction.action?username=x&pwd=y
404报错
ype Status Report

Message /juicy/LoginAction.action

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

-------------------------------------------------------------
login.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>

<body>
<form action="LoginAction.action" >

用户名:<input type="text" name="username"><br>
密码<input type="text" name="pwd"><br>
<input type="submit" value="提交">
</form>
</body>

</html>
-------------------------------------------------------------
web.xml 和struts.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Struts Application</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>

</web-app>



<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">

<!-- START SNIPPET: xworkSample -->

<struts>
<!-- Struts。xml的配置文件 -->
<!-- 所有匹配*.action的请求都由struts2处理 -->
<constant name="struts.action.extension" value="action" />
<!-- 是否启用开发模式 -->
<constant name="struts.devMode" value="true" />
<!-- struts配置文件改动后,是否重新加载 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 请求参数的编码方式 -->
<constant name="struts.i18n.encoding" value="utf-8" />
<!-- 每次HTTP请求系统都重新加载资源文件 -->
<constant name="struts.i18n.reload" value="true" />
<!-- 让struts2支持动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />


<!--新建一个package,name随意,extends自struts-default -->

<package extends="struts-default" name="default" strict-method-invocation="false" >

<action name="LoginAction" method="Login" class="struts.LoginAction">
<result name="success">success.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>

</struts>


<!-- END SNIPPET: xworkSample -->

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
action代码:
package struts;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
//继承ActionSupport类以直接使用SUCCESS, LOGIN等变量和重写execute等方法
//声明用户名和密码的实例变量;
public String username;
public int pwd;
//需要在xml里调用的Login方法(返回值为String):
public String Login(){
System.out.println(username+" "+pwd);
if(username.trim().equals("aaa")&&pwd==123){
return "success";
}else{
return "error";
}
}
//系统生成的get和set方法
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getPwd() {
return pwd;
}
public void setPwd(int pwd) {
this.pwd = pwd;
}
}

tomcat 8.5 struts.xml和web.xml目录如截图
...全文
1902 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
Action和配置都对不上 怎么可以找得到?
故宫遥望 2019-01-27
  • 打赏
  • 举报
回复
引用 10 楼 一生何求的 的回复:
[quote=引用 9 楼 故宫遥望的回复:]问题解决了,web.xml的过滤器写错了
过滤器看起来想没什么问题啊,有什么问题吗[/quote]没有excute 只有prepare 找了半天才发现
故宫遥望 2019-01-27
  • 打赏
  • 举报
回复
引用 12 楼 夜雨痕 的回复:
兄弟,这个有点过时了。。。好好学学spring吧
现在能用就行了
hanchanxhaimao 2019-01-27
  • 打赏
  • 举报
回复
哈哈,看来解决了
maradona1984 2019-01-26
  • 打赏
  • 举报
回复
引用 8 楼 故宫遥望 的回复:
引用 7 楼 stacksoverflow 的回复:
别用struts了
小项目struts够了…

说实话无论小项目大项目都不要用struts了,不好用是其次,特么是用的人少,你出问题都难找到解决方案

小项目直接springboot岂不是更是快速方便?一般来说小项目就是来试验新技术的,拥抱变化嘛
tbywt 2019-01-26
  • 打赏
  • 举报
回复
引用 9 楼 故宫遥望的回复:
问题解决了,web.xml的过滤器写错了
过滤器看起来想没什么问题啊,有什么问题吗
qq_44550377 2019-01-26
  • 打赏
  • 举报
回复
引用 9 楼 故宫遥望的回复:
问题解决了,web.xml的过滤器写错了
哪里写错了,没有看出来
故宫遥望 2019-01-26
  • 打赏
  • 举报
回复
问题解决了,web.xml的过滤器写错了
夜雨痕 2019-01-26
  • 打赏
  • 举报
回复
兄弟,这个有点过时了。。。好好学学spring吧
tbywt 2019-01-25
  • 打赏
  • 举报
回复
是不是package的参数namespace=“”没写啊,试一试看一下
tbywt 2019-01-25
  • 打赏
  • 举报
回复
引用 2 楼 故宫遥望的回复:
引用 1 楼 一生何求的 的回复:
是不是package的参数namespace=“”没写啊,试一试看一下
加过这个 也同样404
你把项目发给我看一下,最近我也刚刚在学习Struts2,1075345220@qq.com
RockeyCui 2019-01-25
  • 打赏
  • 举报
回复
这都 19年了 学点别的吧 别 struts了
110成成 2019-01-25
  • 打赏
  • 举报
回复
我建议把完整项目传上来。。。
故宫遥望 2019-01-25
  • 打赏
  • 举报
回复
引用 1 楼 一生何求的 的回复:
是不是package的参数namespace=“”没写啊,试一试看一下
加过这个 也同样404
故宫遥望 2019-01-25
  • 打赏
  • 举报
回复
引用 7 楼 stacksoverflow 的回复:
别用struts了
小项目struts够了…
stacksoverflow 2019-01-25
  • 打赏
  • 举报
回复
别用struts了
故宫遥望 2019-01-25
  • 打赏
  • 举报
回复
引用 4 楼 RockeyCui 的回复:
这都 19年了 学点别的吧 别 struts了
做自己小项目 暂时不需要最新技术

67,513

社区成员

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

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