准备:使用maven创建struts2项目
1.首先创建index.jsp,主体一行代
<a href="${pageContext.request.contextPath}/hello">第一次使用strut2</a>
2.创建HelloAction
创建方法say,返回String
public String say(){
return "good";
}
3.配置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>
4.配置struts.文件xml
<package name="default" namespace="/" extends="struts-default">
<action name="hello" class="cn.itcast.action.HelloAction"
method="say">
<result name="good">/hello.jsp</result>
</action>
</package>
5.创建hello.jsp
<h1>hello struts</h1>
工作流程如图
maven默认不编译src下面的 .xml文件,需要在pom.xml里面加上
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
點(diǎn)擊查看更多內(nèi)容
5人點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦