struts配置求解
struts2配置环境求解struts struts?2 web.xml java
struts.xml代码
程序代码:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- struts2的action必须放在一个指定的包空间下定义 -->
<package name="default" extends="struts-default">
<!-- 定义处理请求URL为LoginAction.action的Action -->
<action name="LoginAction.do" class="com.action.LoginAction" method="execute">
<!-- 定义处理结果字符串和资源之间的映射关系 -->
<result name="SUCCESS">/success.jsp</result>
<result name="ERROR">/error.jsp</result>
</action>
</package>
</struts>
web.xml
程序代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 定义Struts 2的FilterDispatcher的Filter -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter>
<!-- 定义核心Filter的名字 -->
<filter-name>struts2</filter-name>
<!-- 定义核心Filter的实现类 -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- FilterDispatcher用来初始化Struts 2并且处理所有的Web请求 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
login.jsp
程序代码:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!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=GBK">
<title>登陆页面</title>
</head>
<body>
<form action="/LoginAction" method="post" id="testsub">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="提交">
</form>
</body>
</html>
报错的情况是The requested resource (/struts2/LoginAction.do) is not available.
这是什么情况,调试好一会,哪里有问题?
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!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=GBK">
<title>登陆页面</title>
</head>
<body>
<form action="LoginAction" method="post" id="testsub">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="提交">
</form>
</body>
</html>
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
public String execute(){
System.out.println("12121");
return "SUC";
}
}
<?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-default" extends="json-default">
<action name="LoginAction" class="com.action.LoginAction" method="execute">
<result name="SUC">/success.jsp</result>
<result name="ERROR">/error.jsp</result>
</action>
</package>
</struts>
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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" id="WebApp_ID">
<display-name>stru</display-name>
<filter>
<filter-name>struts2.0</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2.0</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>