这是我的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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>myTest</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>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文件代码:
<!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="test" extends="struts-default">
<action name="TestAction" class="test.MyTest">
<result>/print.jsp</result>
</action>
</package>
</struts>***************************************************************************************
这是我的JAVA文件代码:package test;import com.opensymphony.xwork2.ActionSupport;public class MyTest extends ActionSupport {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute() {
name = "Hello, " + name + "!";
return SUCCESS;
}
}********************************************************************************这是我的主页面index.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>Insert title here</title>
</head>
<body>
<s:form action="TestAction" > //************就是这行***************
Name: <s:textfield name="name" />
<s:submit label="submit"> </s:submit>
</s:form>
</body>
</html>***************************************************************************************问题:
我的主页面index.jsp中就是打注释的那行有问题(有个红差差),说什么“The value [TestAction] for attribute [action] in tag [form] is not valid.”
在网上查了一下,有人说有个红差不要紧也能跑,我就去试了一下,
结果:
HTTP Status 404 - /myTest/TestAction--------------------------------------------------------------------------------type Status reportmessage /myTest/TestActiondescription The requested resource (/myTest/TestAction) is not available.请知道的达人能不能指点一下,小弟就这问题已经搞了一整天了
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>myTest</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>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文件代码:
<!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="test" extends="struts-default">
<action name="TestAction" class="test.MyTest">
<result>/print.jsp</result>
</action>
</package>
</struts>***************************************************************************************
这是我的JAVA文件代码:package test;import com.opensymphony.xwork2.ActionSupport;public class MyTest extends ActionSupport {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute() {
name = "Hello, " + name + "!";
return SUCCESS;
}
}********************************************************************************这是我的主页面index.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>Insert title here</title>
</head>
<body>
<s:form action="TestAction" > //************就是这行***************
Name: <s:textfield name="name" />
<s:submit label="submit"> </s:submit>
</s:form>
</body>
</html>***************************************************************************************问题:
我的主页面index.jsp中就是打注释的那行有问题(有个红差差),说什么“The value [TestAction] for attribute [action] in tag [form] is not valid.”
在网上查了一下,有人说有个红差不要紧也能跑,我就去试了一下,
结果:
HTTP Status 404 - /myTest/TestAction--------------------------------------------------------------------------------type Status reportmessage /myTest/TestActiondescription The requested resource (/myTest/TestAction) is not available.请知道的达人能不能指点一下,小弟就这问题已经搞了一整天了
不用include
HTTP Status 404 - /myTest/TestAction--------------------------------------------------------------------------------type Status reportmessage /myTest/TestActiondescription The requested resource (/myTest/TestAction) is not available.
你访问方式错了吧
直接是http://localhost:端口/项目名称
首先出来的应该是index.jsp
提交表单后转到print.jsp
freeer-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.14.jar
xwork-2.0.7.jar基础的struts2练习这几个jar就够了,多了可能有冲突。
这一行的test改成myTest试试
楼主你这样看看 ,你把package的namespace
<package name="test" extends="struts-default" namespace="/test">
<action name="TestAction" class="test.MyTest">
<result>/print.jsp </result>
</action>
</package> <s:form action="TestAction" namespace="/test">
把method也给加上,别用默认行为,这样看看。。
现在才注意到这点上来
struts.xml文件是要放在src下