Struts配置應用1
阿新 • • 發佈:2017-10-24
turn lns ati @override author name rep sun soft
一.導包
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.13</version>
</dependency>
二.配置struts.xml文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!DOCTYPE struts PUBLIC 4 "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" 5"http://struts.apache.org/dtds/struts-2.5.dtd"> 6 <struts> 7 <package name="default" extends="struts-default" namespace="/"> 8 <action name="demo" class="com.yztc.demo.action.DemoAction"> 9 <result name="index" >index.jsp</result> 10 </action> 11</package> 12 </struts>
三.配置web.xml文件
1 <!DOCTYPE web-app PUBLIC 2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 3 "http://java.sun.com/dtd/web-app_2_3.dtd" > 4 5 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 7xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 8 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 9 version="3.1"> 10 <filter> 11 <filter-name>struts2</filter-name> 12 <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> 13 </filter> 14 <filter-mapping> 15 <filter-name>struts2</filter-name> 16 <url-pattern>/*</url-pattern> 17 </filter-mapping> 18 </web-app>
四.創建一個class繼承ActionSupport,如下:
1 package com.yztc.demo.action; 2 3 import com.opensymphony.xwork2.ActionSupport; 4 5 /** 6 * _ooOoo_ 7 * o8888888o 8 * 88" . "88 9 * (| -_- |) 10 * O\ = /O 11 * ___/`---‘\____ 12 * . ‘ \\| |// `. 13 * / \\||| : |||// 14 * / _||||| -:- |||||- 15 * | | \\\ - /// | | 16 * | \_| ‘‘\---/‘‘ | | 17 * \ .-\__ `-` ___/-. / 18 * ___`. .‘ /--.--\ `. . __ 19 * ."" ‘< `.___\_<|>_/___.‘ >‘"". 20 * | | : `- \`.;`\ _ /`;.`/ - ` : | | 21 * \ \ `-. \_ __\ /__ _/ .-` / / 22 * ======`-.____`-.___\_____/___.-`____.-‘====== 23 * `=---=‘ 24 * ............................................. 25 * 26 * @author bindu 27 * @date 2017-10-23 20:31 28 */ 29 30 31 public class DemoAction extends ActionSupport { 32 @Override 33 public String execute() throws Exception { 34 System.out.println("你死不死啊!!!"); 35 return "index"; 36 } 37 }
Struts配置應用1