eclipse struts2找不到action!调了一个晚上了

chaoliu1024 2013-01-21 10:01:14
原来都是在myEclipse上做开发的,今天换了eclipse想试试,总找不到action,调了一个晚上,所以上来求助大家。
文件结构如下图

web.xml配置代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Struts2</display-name>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

struts.xml配置代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" extends="struts-default">

<action name="struts" class="org.action.StrutsAction">
<result name="success">/welcome.jsp</result>
<result name="error">/hello.jsp</result>
</action>
</package>
</struts>

hello.jsp页面代码
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>struts 2 应用</title>
</head>
<body>
<form action="struts.aciton" method="post">
请输入姓名:<input type="text" name="name"/><br>
<input type="submit" value="提交"/>
</form>
</body>
</html>

Action Java代码
package org.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class StrutsAction extends ActionSupport{

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String execute() throws Exception {
if(!name.equals("HelloWorld")){
Map request = (Map)ActionContext.getContext().get("request");
request.put("name", getName());
return SUCCESS;
}
else{
return ERROR;
}
}
}

报错如下图

不知道哪里有问题!找了很久了
...全文
520 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
speeder 2013-01-23
  • 打赏
  • 举报
回复
把拼错的改过来,再重启tomcat,再试。
乃刀的青春 2013-01-22
  • 打赏
  • 举报
回复
引用 9 楼 fw347969680 的回复:
引用 6 楼 wjg19890301 的回复:<form action="struts.aciton" method="post"> action拼写错误,还有你的jsp是在WEB-INF目录下面了把. 这样的话你struts.xml里面的配置就需要改成/WEB-INF/hello.jsp 这个jsp是在不在WEB-INF目录下面真心看不出来。
是啊.只有楼主自己知道.看样子是在WEB-INF下了
yzsunlight 2013-01-22
  • 打赏
  • 举报
回复
首先看你的项目能不能在tomcat里访问。然后你的action写错了,应该是struts.action而不是struts.aciton
andy_swc 2013-01-22
  • 打赏
  • 举报
回复
LZ 要细心呀
fw347969680 2013-01-22
  • 打赏
  • 举报
回复
引用 6 楼 wjg19890301 的回复:
<form action="struts.aciton" method="post"> action拼写错误,还有你的jsp是在WEB-INF目录下面了把. 这样的话你struts.xml里面的配置就需要改成/WEB-INF/hello.jsp
这个jsp是在不在WEB-INF目录下面真心看不出来。
libinkukuku 2013-01-22
  • 打赏
  • 举报
回复
你form里面的action()应该和xml中的action名字一致然后通过配置文件xml找到 class类 跳转到class
dw_java08 2013-01-22
  • 打赏
  • 举报
回复
引用 3 楼 JasonSSH 的回复:
<form action="struts.aciton" method="post"> 留意你的action打错了!
乃刀的青春 2013-01-22
  • 打赏
  • 举报
回复
<form action="struts.aciton" method="post"> action拼写错误,还有你的jsp是在WEB-INF目录下面了把. 这样的话你struts.xml里面的配置就需要改成/WEB-INF/hello.jsp
悲催的程序猿 2013-01-22
  • 打赏
  • 举报
回复
引用 3 楼 JasonSSH 的回复:
<form action="struts.aciton" method="post"> 留意你的action打错了!
+1
tomatozq 2013-01-22
  • 打赏
  • 举报
回复
package中最好把namespace="/"加上
NoTargetException 2013-01-22
  • 打赏
  • 举报
回复
<form action="struts.aciton" method="post"> 留意你的action打错了!
brightyq 2013-01-21
  • 打赏
  • 举报
回复
<form action="struts.aciton" method="post"> 这里action的名称是struts.aciton struts.xml中 <action name="struts" class="org.action.StrutsAction"> 名称确是struts 楼主粗心哪。 另外,名称不要叫struts,叫个其它有意义的名称不好吗。

81,092

社区成员

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

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