1.导包
导入相应的jar包,在blank项目中会出现
2.书写Action类
package com.littlepage.struts; public class HelloAction { public String hello() { System.out.println("HelloWorld"); return "success"; } }
3.书写src/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> <package name="hello" namespace="/popopo" extends="struts-default"> <action name="HelloAction" class="com.littlepage.struts.HelloAction" method="hello"> <result name="success">/hello.jsp</result> </action> </package> </struts>
4.将struts2核心Filter配置到web.xml
<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>