Struts2.0报错HTTP Status 404 - /Struts2_HelloWorld/HelloWorld

HTTP Status 404 - /Struts2_HelloWorld/HelloWorld


type Status report

message /Struts2_HelloWorld/HelloWorld

description The requested resource (/Struts2_HelloWorld/HelloWorld) is not available.


Apache Tomcat/6.0.13

***********************************************************************************************

开发环境:

JDK:jdk1.5.0_11

Tomcat:apache-tomcat-6.0.13

Eclipse Platform:Version: 3.3.0 Build id: I20070625-1500 

Struts:struts-2.0.9

***********************************************************************************************

web.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 Blank</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</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-list>

</web-app>

***********************************************************************************************

struts.xml

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
 <include file="struts-default.xml" />
 <package name="tutorial" extends="struts-default">
  <action name="HelloWorld" class="tutorial.HelloWorld">
   <result>HelloWorld.jsp</result>
  </action>
 </package>
</struts>

***********************************************************************************************

SayHello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ 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=ISO-8859-1">
<title>Say Hello</title>
</head>
<body>
<h3>Say "Hello" to:</h3>
<s:form action="HelloWorld">
            Name: <s:textfield name="name" />
 <s:submit />
</s:form>

</body>
</html>

***********************************************************************************************

HelloWorld.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ 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=ISO-8859-1">
<title>Hello</title>
</head>
<body>
<h3><s:property value="name" /></h3>
</body>
</html>

***********************************************************************************************

HelloWorld.java

package tutorial;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {
 private static final long serialVersionUID = 1L;


 private String name;

 public String getName() {
  return name;
 }

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

 public String execute() {
  name = "Hello, " + name + "!";
  return SUCCESS;
 }
}
***********************************************************************************************

运行http://localhost:8080/Struts2_HelloWorld/SayHello.jsp,就会报HTTP Status 404 - /Struts2_HelloWorld/HelloWorld的错误。

http://localhost:8080/Struts2_HelloWorld/HelloWorld.action可以看到:

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

There is no Action mapped for namespace / and action name HelloWorld. - [unknown location]
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
	org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
	org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)

 

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.

***********************************************************************************************

解决:struts.xml文件名错误,改正后http://localhost:8080/Struts2_HelloWorld/HelloWorld.action可以看到

Hello, null!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值