标签:
1、将Struts2的基本jar包拷到工程的lib目录中
2、配置web.xml,加载Struts2的过滤器
<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>
3、加载Struts的配置文件Struts.xml到src目录
<?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> <!-- struts常量 --> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <constant name="struts.action.extension" value="action,,"></constant> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <constant name="struts.configuration.xml.reload" value="true"></constant> <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant> <package name="default" namespace="/" extends="struts-default"> </package> </struts>
4、开发Struts中的Action类,类中必须有execute方法
5、第一个Action
Java代码:
package com.action; public class FirstAction { public String execute(){ System.out.println("hello Strust2!"); return null; } }
Struts.xml
<package name="default" namespace="/" extends="struts-default"> <action name="FirstAction" class="com.action.FirstAction"></action> </package>
jsp页面
<a href="<%=path %>/FirstAction" >hello Struts2</a>
标签:
原文地址:http://www.cnblogs.com/Arvin-9/p/4649950.html