您的位置:首页 > 理论基础 > 计算机网络

[ 2222 ]http://e.eqxiu.com/s/wJMf15Ku

2015-12-23 19:48 597 查看
实例处理流程图

客户端 -请求-》 Struts2过滤器 StrutsPrepareAndExcuteFilter 

-转发-》Action对象first

-返回-》视图first.jsp

 

Struts类库介绍 

struts2-core-xxx.jar -- Struts2的核心类库

xwork-core-xxx.jar -- Xwork的核心类库

ognl-xxx.jar -- Ognl(Object Graph Navigation Language)表达式语言类库

commons-logging-xxx.jar -- Log4j日志支持类库

freemarker-xxx.jar -- Freemarker模板语言支持类库

commons-io-xxx.jar --  处理IO操作的工具类库

commons-fileupload-xxx.jar -- 文件上传支持类库

 

Struts2的结构体系图



 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>8.1</display-name>
<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>
<!-- Struts2过滤器 -->
<filter>
<!-- 过滤器名称 -->
<filter-name>struts2</filter-name>
<!-- 过滤器类 -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- Struts2过滤器映射 -->
<filter-mapping>
<!-- 过滤器名称 -->
<filter-name>struts2</filter-name>
<!-- 过滤器映射 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

 struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 声明包 -->
<package name="myPackage" extends="struts-default">
<!-- 定义action -->
<action name="first">
<!-- 定义处理成功后的映射页面 -->
<result>/first.jsp</result>
</action>
</package>
</struts>

 index.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>主页</title>
</head>
<body>
<a href="first.action">请求Struts2</a>
</body>

</html>

 first.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>第一个Struts2程序</title>
</head>
<body>
第一个Struts2程序!
<br>
</body>
</html>

 index.jsp页面



 first.jsp 页面



 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: