Struts2概述
1 struts2框架应用javaee三层结构中web层框架
2 struts2框架在Struts1和webwork基础之上发展全新的框架
3struts2 能解决的问题
Struts2
第一步 导入jar包
(1)在lib中有jar包 不能把这些jar都导入到项目中
(2)到apps目录里面,找到实例程序,
第二步创建Action
package com.netxintai.action; public class UserAction { /** * 访问Action,每次访问action时候,默认的访问方法是execute方法 * */ public String execute(){ System.out.println("当你看到这条信息,说明你配置的最简单的struts2已经成功"); return "ok"; } }
第三步 配置Action路径
1,创建一个Struts2核心配置文件,核心配置文件名称和位置是固定的
位置必须在src下面struts.xml;
2,引入dtd约束
<?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> <package name="default" namespace="/" extends="struts-default"> <action name="useraction" class="com.netxintai.action.UserAction"> <result name="ok">/index.jsp</result> </action> </package> </struts>
4 配置struts2过滤器
<?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>struts2day01</display-name> <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> <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>
至此就可以运行项目直接在地址栏输入路径http://localhost:8080/struts2day01/useraction如果出现如下代码说明你已经配置好了struts2开发环境
Hello there, just became aware of your blog through Google, and found that it is really informative.
I’m gonna watch out for brussels. I will be grateful if you continue this
in future. A lot of people will be benefited from your writing.
Cheers! Najlepsze escape roomy
Very interesting topic, thank you for putting up.!