使用流程:

1、引入Struts 2的库文件:

将“common-logging-1.0.4.jar”、“freemaker-2.3.8.jar”、“struts2-core-2.0.11.1.jar”、“xwork-2.0.4.jar”和“ognl-2.6.11.jar”类库复制到Web项目的WEB-INF/lib目录下。

2、编辑Web项目中的“web.xml”配置文件,在配置文件中增加Struts 2核心Filter的配置:

3.0" 
	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_3_0.xsd">
  <display-name></display-name>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- 定义核心Filter -->
  <filter>
  	<!-- 定义核心Filter的名称 -->
  	<filter-name>struts2</filter-name>
  	<!-- 定义核心Filter的实现类 -->
  	<filter-class>
  		org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  	</filter-class>
  </filter>
  <filter-mapping>
  	<!-- 定义核心Filter的名称 -->
  	<filter-name>struts2</filter-name>
  	<!-- 使用该核心Filter来接受所有的Web请求 -->
  	<url-pattern>/*</url-pattern>
  </filter-mapping></web-app>

 

3、新建控制器类Action

 

4、配置Action,修改struts.xml,其中包括指定Action的实现类以及Action处理结果与视图资源文件之间的映射:

-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<!-- Action必须放在指定的包命名空间中 -->
	<package name="structs2" extends="struts-default">
		<!-- 定义login的Action,其实现类为com.chaos.structs2.action.LoginAction -->
		<action name="aaa" class="com.chaos.structs2.action.LoginAction">
			<!-- 定义处理结果与视图资源之间的关系 -->
			<result name="success">/login_success.jsp</result>
			<result name="error">/login_error.jsp</result>
		</action>
	</package>
</struts>    



相关文章:

  • 2021-05-03
  • 2021-08-27
  • 2021-04-11
  • 2022-12-23
  • 2022-01-23
  • 2021-08-02
  • 2021-06-25
  • 2021-11-28
猜你喜欢
  • 2021-09-22
  • 2021-11-08
  • 2022-12-23
  • 2021-11-23
  • 2021-05-25
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案