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

来源:互联网 发布:mysql小于号转义 编辑:程序博客网 时间:2024/05/22 07:22

一、创建一个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,返回成功。

原创粉丝点击