为了账号安全,请及时绑定邮箱和手机立即绑定

JAVA_Struts2学习小计

标签:
Java

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;
}

}

点击查看更多内容
2人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消