新手刚学struts2弄好久了struts.xml文件配置:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="hb" namespace="/bin" extends="struts-default">
<action name="helloworld" class="cn.bin.huang.struts2.HelloWorldAction" method="execute">
<result name="success">/pages/hello.jsp</result>
</action>
</package>
</struts>
web.xml文件配置:<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
HelloWorldAction.java:
package cn.bin.huang.struts2;public class HelloWorldAction {
private String msg;
public String getMessage() {
return msg;
} public String execute(){
msg="这是我第一个Struts2应用";
return "success";
}
}
报的错:
HTTP Status 404 - /struts2/bin/helloworld--------------------------------------------------------------------------------type Status reportmessage /struts2/test/helloworlddescription The requested resource (/struts2/bin/helloworld) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.18
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="hb" namespace="/bin" extends="struts-default">
<action name="helloworld" class="cn.bin.huang.struts2.HelloWorldAction" method="execute">
<result name="success">/pages/hello.jsp</result>
</action>
</package>
</struts>
web.xml文件配置:<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
HelloWorldAction.java:
package cn.bin.huang.struts2;public class HelloWorldAction {
private String msg;
public String getMessage() {
return msg;
} public String execute(){
msg="这是我第一个Struts2应用";
return "success";
}
}
报的错:
HTTP Status 404 - /struts2/bin/helloworld--------------------------------------------------------------------------------type Status reportmessage /struts2/test/helloworlddescription The requested resource (/struts2/bin/helloworld) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.18
你filter改成这个试一试看看
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'hello.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
${message} <br>
</body>
</html>
我加了.action访问也没用 正在重新写工程 ,把以前的删掉试试
我的工程是struts2,但在webapps文件里会生成一个struts2和不知道哪来的structs文件原来是我之前的工程名是structs,后来直接在myeclipse里改成struts2,而structs他就一直存在而且我重启myeclipse都没用,全删除后重新建立struts2工程后现在可以了。。成功了!!!谢谢大家的关注,非常感激!!!