首先Struts有三个必要的前期准备工作:jar包,web.xml配置,struts.xml配置
jar包:来提供一些基础的struts方法和配置
web.xml:struts是由filter来启动的,所以要在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>
struts.xml:这里是框架最核心的部分,因为你的所有请求都会经由这里来连接方法,
前端请求 --> struts -->处理方法 -->返回struts -->传递
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default" >
<action name="要传递的页面,这里要与前台中(href,action等)一致" class="路径" method="方法名">
<result name="方法的返回字符串,根据此字符串">要处理的事</result>
</action>
</package>
</struts>
这就是简单的struts环境构建