一、导包
11个jar包,最好在WebRoot下面的lib中配置一份
二、配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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.jsp</welcome-file>
</welcome-file-list>
</web-app>
可以默认的配置,长这样,可以从struts2下载的包里面有个blank的demo中解压出来。
web.xml一般位于 WebRoot/WEB-INF/下面
三、配置Struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hello">
<result>
/index.jsp
</result>
</action>
</package>
</struts>
此处要注意的是namespace的写法,此种写法在访问的时候即写入“/”,如图:
若是改成:
<package name="default" namespace="/a" extends="struts-default">
<action name="hello">
<result>
/index.jsp
</result>
</action>
</package>
则输入为:
注意:程序中并没有指定action="hello"的类,所以在浏览器中要输入 ****.action进行访问
框架这种东西不用一会就忘了....表示之前看的忘得差不多了,可怜我的jsp/Servlet/html.../(ㄒoㄒ)/~~忘完了.....