9
回答
Tomcat7+struts2出现There is no Action mapped for action name welcome.
这是struts.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>
	<package name="helloWorld" extends="struts-default" namespace="day01">
		<action name="welcome" class="test.WelcomeAction">
			<result name="success">/WEB-INF/welcome.jsp</result>
			<result name="fail">/WEB-INF/nameForm.jsp</result>
		</action>
	</package>
</struts>

---------------------------------------------------------------------------------
这是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>Cat</display-name>
  <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>
--------------------------------------------------------------------------------------
这是WelcomeAction.java文件
package test;

public class WelcomeAction{
	private String name;
	
	public String showYourName(){
		System.out.print("Your Name is : ");
		System.out.println(name);
		
		if("monster".equalsIgnoreCase(name)){
			return "fail";
		}
		return "success";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
--------------------------------------------------------------------
以下是2个jps页面
--------------------nameForm.jsp---------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="/test/day01/welcome.action" method="post">
		<input type="text" name="name">
		<input type="submit" value="SUBMIT">
	</form>
</body>
</html>

--------------------------------------------------------------------------
----------welcome.jsp---------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h2>Welcome, ${name}</h2>
</body>
</html>
目录结构如下:
WEB-INF目录下有classes目录,不知道为什么在视图里面没出现,我在工作区里面可以找到classes目录,里面还有struts.xml文件




举报
55wish
发帖于5年前 9回/2K+阅
顶部