Struts2关于Action的系统训练1
来源:互联网 发布:微信美化软件 编辑:程序博客网 时间:2024/05/01 02:19
这篇教程主要讲解了Struts中Action的一些知识点,通过对一些知识的了解从而掌握Action的使用和一些原理。废话不多说,下面就直接看我的训练步骤:
1安装myeclipse,tomcat。
2下载Struts文件压缩包,并解压到本地硬盘,
3使用myeclipse建立一个web project,使用javaee5.0,给项目配置jdk和tomcat服务器
4在src文件夹里添加Struts.xml配置文件,配置内容如下
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><span style="color:#ff0000;"><constant name="struts.devMode" value="true" /></span> <package name="default" namespace="/" extends="struts-default"> <action name="hello"> <result> /Hello.jsp </result> </action> </package></struts></span>
其中红色部分是打开开发模式,这样改变配置文件就不用重启tomcat加载项目,默认是关闭。action名字为hello,结果是hello.jsp,
5,在WEB-INF文件夹下lib文件中添加Struts的jar包,包括
1)xwork-core-2.1.62)struts2-core-2.1.83)ognl-2.7.34)freemarker-2.3.155)commons-io-1.3.26)commons-fileupload-1.2.1
6下面是hello.jsp页面内容
<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><span style="color:#ff0000;"><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%</span>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <span style="color:#ff0000;"> <base href="<%=basePath%>"></span> <title> Hello Struts2</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> Hello Struts2! <br> </body></html></span>
7web.xml文件的配置文件为:
<span style="font-size:18px;"><?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" 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>Struts2_0100_Introduction</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <span style="color:#ff0000;"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></span></web-app></span>
8在地址栏输入http://localhost:8080/项目名/hello.action就会打开hello.jsp页面,
首先看http://localhost:8080/项目名/hello.action。客户端发送一个url到tomcat,tomcat根据项目配置文件web.xml找filter,首先查看<url-pattern>/*</url-pattern>,映射到
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>这个类中,然后根据Struts.xml配置文件中的action名称为hello,就运行Action的方法,返回内容指引到hello.jsp页面。返回给用户。
10这是最简单的流程。慢慢理解一下,然后接下来的训练会逐渐添加要点。
0 0
- Struts2关于Action的系统训练1
- Struts2关于Action的系统训练2关于命名空间
- Struts2关于Action的系统训练5关于使用通配符来控制action方法的使用
- Struts2关于Action的系统训练6关于action接收参数的三种方法
- Struts2关于Action的系统训练7关于action接收参数的第三种方法
- Struts2关于Action的系统训练3关于Action创建和path路径问题
- Struts2关于Action的系统训练8关于OGNL表达式的理解
- Struts2关于Action的系统训练4关于动态方法调用DMI
- 01-Struts2创建系统的Action代理
- 关于Struts2中Action的一些总结
- 关于struts2 的s:action标签
- 关于struts2中<s:action>的问题
- 关于Struts2框架action后缀的问题
- struts2中关于action的使用说明
- 关于spring3无法注入struts2的action
- struts2--关于action的几种方法
- Struts2.5关于<s:action.../>标签找不到Action的问题
- 关于struts2中的action
- WPF 中Binding的2个属性Source与ElementName的区别
- Find Minimum in Rotated Sorted Array II(LeetCode)
- 花生壳 for linux的安装以及使用
- 哎,我今年28,9岁
- C++11显式转换操作符
- Struts2关于Action的系统训练1
- DB2 SQL300081-08001错误解决办法
- Java以及JS 手机号当中4位用“*”代替
- 跨界的艺术
- Android Studio 快捷键
- 浅谈C++中指针和引用的区别
- android之SharedPreferences应用
- ORACLE中的SGA和PGA
- Ubuntu中复制文件或目录的命令