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


    Struts Blank

   
        struts2
        org.apache.struts2.dispatcher.FilterDispatcher
   

   
        struts2
        /*
   

   
        index.html
   

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

struts.xml

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

 
 
  
   HelloWorld.jsp
  

 

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

SayHello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>




Say Hello


Say "Hello" to:



            Name:
 


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

HelloWorld.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>




Hello




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

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!

你可能感兴趣的:(技术,Struts)