Struts 2 框架搭建HelloWorld

1.导包

导入相应的jar包,在blank项目中会出现

Struts 2 框架搭建HelloWorld

2.书写Action类

package com.littlepage.struts;

public class HelloAction {
public String hello() {
System.out.println("HelloWorld");
return "success";
}
}

3.书写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="/popopo" extends="struts-default">
<action name="HelloAction" class="com.littlepage.struts.HelloAction" method="hello">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>

4.将struts2核心Filter配置到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>

5.访问localhost:8080/项目名/namespace/actionname

Struts 2 框架搭建HelloWorld

上一篇:MySQL(动态执行SQL)


下一篇:WebUploader UEditor chrome 点击上传文件选择框会延迟几秒才会显示 反应很慢