Struts2核心文件配置与 xml文件配置基础版
来源:互联网 发布:挂号系统源码 编辑:程序博客网 时间:2024/05/29 17:05
struts框架必备的三个要素:
1.xml文件配置:
xml文件配置主要为一个过滤器的配置:StrutsPrepareAndExecuteFilter;
该过滤器为struts默认为我们实现好了的;所以在xml文件中直接配置,不用去自己建过滤器filter;
配置如下:
<?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_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>web_Struts2</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-list></web-app>
在此环境下得struts才能应用;
2.struts核心文件配置:
struts.xml动态文件配置如下:
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"><struts><!-- package name="student"和java的包一样,命名唯一,将要执行的类同一进行管理 ,可以有多个包 --><!-- namespace="/"代表命名空间为根空间;命名空间就是我们在发起一个请求的时候输入的地址比如:http://localhost:8080/web_Struts2/user.action;如果是"/"为根空间;如果为http://localhost:8080/web_Struts2/随意一个名字/user.action;那么namespace="随意一个名字" --><!-- ction name="user" user和servlet类似有一个名称,用于调用时候输入地址;后缀默认为.action!! 且后缀名任意更改在struts.properties文档中可任意更改名字 --><!-- class="com.ygr.struts.action.UserAction"所在的包地址,和在xml文档中配置servlet一样 --><!-- method="add" 这里如果不写,默认执行的方法就是execute();如果写了就是执行所写的方法,这里就是执行add方法 --><!-- result name="success" 这里和对应的java,action类调用的方法相对应-->
<package name="student" namespace="/" extends="struts-default"><action name="user" class="com.ygr.struts.action.UserAction"method="add"><result name="success">/success.jsp</result><result name="add">/add.jsp</result></action></package></struts>另外还有静态文件配置:如下:
文件类型名称为:struts.properties
#更改struts2后缀;默认一般为action 但是可以随意更改为其他后缀比如do;jspa等等struts.action.extension=action
3.对应实现的action类包名:com.ygr.struts.cation
对应的java类为:
package com.ygr.struts.action;import org.apache.log4j.Logger;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport {private static Logger log=Logger.getLogger(UserAction.class);@Overridepublic String execute() throws Exception {/** * 请求响应 * 执行业务处理 * 返回响应 */log.debug("执行execute()方法>>>>>>");return "success";}public String add(){log.debug("执行add()方法 >>>>>>");return "add";}}
注:要想实现struts2框架的你的工程李必须导入的几个包为:
少一个都会报错。
0 0
- Struts2核心文件配置与 xml文件配置基础版
- struts2 xml文件配置
- Struts2 配置xml文件
- [Struts2]配置 web.xml文件
- 配置Struts2 web.xml文件
- struts2配置web.xml文件
- Struts2配置struts.xml文件
- 配置安装Struts2 web.xml文件
- Struts2 Chapter2 struts.xml文件的配置
- struts2配置 struts.xml文件范例
- Struts2关于struts.xml文件配置说明
- MyEclipse10 配置struts2.xml文件自动提示
- mybatis的核心xml文件配置mybatis-config.xml
- struts2基础学习之文件配置
- Struts2核心配置文件“struts.properties”文件的配置
- Struts2框架(一)架构、文件配置、核心API详解
- struts2环境配置以及配置xml文件智能提示
- Struts2的学习(1)--Struts2.xml文件的配置
- 我的服务器开发之路-showdoc的升级
- String和StringBuffer的区别
- 《第一行代码(第二版)》学习(二)
- 第27次闰秒事件··就问运维小哥慌不慌
- python逐行读取文件内容的三种方法
- Struts2核心文件配置与 xml文件配置基础版
- 什么是分布式系统(通俗易懂的说法)
- Java Object Clone
- startsWith(),endsWith()的作用和用法
- Android Studio无法连接夜神模拟器
- Java ClassCastException
- 【TensorFlow】TensorFlow 的卷积神经网络 CNN - 无TensorBoard版
- Linux设备驱动二 (3)进程调度相关概念
- windows安装多个Apache