Struts2之快速入门

下载Struts2

百度各种搜索下载Hibernate

下载解压缩之后,可以看到如下目录结构:  

其中lib文件夹下会有Struts2开发中所有可能用到的JAR包,然而实际开发中,并不需要引入那么多JAR包,我们只需要将apps文件夹下的struts2-blank.war(空的工程)解决后,找到其lib包下的JAR包引入即可

Struts2相关配置

  • Action类 

public class HelloAction {
	
	public String hello(){
		
		System.out.println("hi,mark");
		
		return "success";
	}
}
  • 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="/hello" extends="struts-default">
		<action name="HelloAction" class="com.mark.test.HelloAction" method="hello">
			<result name="success">/hello.jsp</result>
		</action>
	</package>
</struts>
  • web.xml--Struts2核心过滤器配置

  <!-- Struts2核心过滤器 -->
  
  <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>

运行测试

猜你喜欢

转载自blog.csdn.net/mmake1994/article/details/81569297
今日推荐