1、导入Jar包
2、配置web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 5 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 6 <welcome-file-list> 7 <welcome-file>login.jsp</welcome-file> 8 </welcome-file-list> 9 10 <filter> 11 <filter-name>struts2</filter-name> 12 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 13 </filter> 14 15 <filter-mapping> 16 <filter-name>struts2</filter-name> 17 <url-pattern>/*</url-pattern> 18 </filter-mapping> 19 20 </web-app>
3、初始化Action继承ActionSupport
4、配置struts.xml
<?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> <!-- 启动开发者模式,便于调试 --> <constant name="struts.devMode" value="true"/> <package name="hello" namespace="/hello" extends="struts-default"> <action name="main" class="com.aaron.action.HelloAction"> <result>/WEB-INF/jsp/main.jsp</result> </action> </package> </struts>
5、jsp的目录结构
6、结果显示
Index.jsp
Main.jsp