当前位置: 代码迷 >> Java Web开发 >> struts2的有关问题(头疼)
  详细解决方案

struts2的有关问题(头疼)

热度:200   发布时间:2016-04-17 10:56:13.0
struts2的问题(头疼)
昨天想部署个struts2的helloworld工程,一直不行,各位大牛帮小弟看看,多谢
名为HelloWorld.java的action:
package test;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {
/**

*/
private static final long serialVersionUID = 1L;
public String message;
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}

/**
* @return the message
*/
public String getMessage() {
return message;
}
@Override
public String execute(){
message = "Hello World!!!";

return SUCCESS;
}
}

名为result.jsp显示helloworld的jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%>
  <%@taglib uri= "/struts-tags" prefix ="s"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<s:property value="message" />

</body>
</html>

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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>Test</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

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="test" extends="struts-default">
<action name="HelloWorld" class="test.HelloWorld">
<result>result.jsp</result>
</action>
</package>
</struts>

在浏览器里输入http://localhost:8080/Test/HelloWorld.action
或者http://localhost:8080/Test/result.jsp

最后画面结果总是
HTTP Status 404 - 

--------------------------------------------

type Status report

message 

description The requested resource () is not available.


--------------------------------------------

Apache Tomcat/5.5.31

啥问题啊,想不出来,各位大牛帮帮小弟吧,谢谢

------解决方案--------------------
启动的时候控制台有没有报错?如果启动报错,那么不管你访问什么都是404。
------解决方案--------------------
很可能是你启动tomcat的时候就出错了,如果显示的错误是找不到class
  相关解决方案