标签:eth 之间 html ror http 工作 调用 控制 web
一、Struts2工作原理
如下图:

二、Struts2配置文件
1、web.xml
任何MVC框架都需要与Web应用整合,这就不得不借助于web.xml文件,只有配置了web.xml文件的Servlet才会被应用加载
通常,所有的MVC框架都需要Web应用加载一个核心控制器,对于Struts2框架而言,需要加载StrutsPrepareAndExecuteFilter,StrutsPrepareAndExecuteFilter加载Struts框架。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>MyStruts2</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</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>
2、struts.xml
struts2的核心配置文件,负责管理应用中的Action映射,以及该Action包含的Result定义等。
内容包括:
1) 全局属性
2) 用户请求和响应Action之间的对应关系
3) Action可能用到的参数和返回结果
4) 各种拦截器
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="com.example.struts2.LoginAction" method="login">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
<result name="result">/result.jsp</result>
</action>
</package>
</struts>
3、struts.properties
struts2框架的全局属性文件,自动加载。该文件包含很多key-value对。
该文件完全可以配置在struts2.xml文件中,使用constant元素
标签:eth 之间 html ror http 工作 调用 控制 web
原文地址:https://www.cnblogs.com/linlf03/p/11462424.html