Struts2学习(一)——第一个项目

一、创建一个web工程,并导入相关jar包,(可以直接从struts-2.3.1.2\apps下的struts2-blank.war中的WEB-INF/lib目录下去copy)



二、创建Action:

public class HelloWorldAction implements Action{

	public String execute() throws Exception {
		System.out.println("HelloWorld!");
		return SUCCESS;
	}
}


三、新建success.jsp


四、在src目录下新建struts.xml,配置如下(配置的具体含义以后再一一介绍):

<?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="" namespace="/" extends="struts-default">
		<action name="helloworld" class="com.test.struts2.HelloWorldAction">
			<result name="success">success.jsp</result>
		</action>
	</package>
</struts>


五、配置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>



六、部署测试:

http://localhost:8080/struts2/helloworld.action,返回成功。

猜你喜欢

转载自blog.csdn.net/lxpblsc/article/details/16806217