1、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>HelloWorldStruts2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2、struts2.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">
<!-- url-action-method(exacute())-result(view) -->
<struts>
<!-- namespace URL的逻辑路径 -->
<package name="test" namespace="/first" extends="struts-default">
<!-- action中name可以支持通配符 如hello_* method='{1}'-->
<action name="hello" class="com.pluto.action.HelloWorld">
<!-- 可以有多个result 根据action方法返回值与指定的name值匹配
返回相应视图 -->
<result name="success_say">/helloworld.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
3、action类
package com.pluto.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport
{
private String uname;
@Override
public String execute() throws Exception
{
return "success_say";
}
public String getUname()
{
return uname;
}
public void setUname(String uname)
{
this.uname = uname;
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章