struts2(第一个小程序)

                                  第一个用Struts2做的一个Hello程序

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
<!-- Struts2前端控制器StrutsPrepareAndExecuteFilter 会去找Struts.xml文件-->
  <filter>
        <filter-name>action2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
     <filter-mapping>
        <filter-name>action2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

注意: 在struts.xml文件中,配置HelloAction.(把HelloAction交给Struts框架管理)


lib包:

    导入mini所有的包

项目目录结构:

    


HellowAction:

package clu.mochunrong.action;

public class HellowAction {
public String sing(){
	System.out.println("你好师姐 ");
return "abc";
}
}

Strut2: 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
   <package name="helloPkg" extends="struts-default" namespace="/a">
   <action name="b" class="clu.mochunrong.action.HellowAction" method="sing">
   <result name="abc" type="dispatcher">
   <param name="location">/views/jsp/index.jsp</param>
   </result>
   </action>
   </package>
</struts>
<!-- 

   <package name="自定义命名" extends="struts-default" namespace="/命名空间">  
   <action name="资源名称" class="Struts2管理的类的权限类名" method="sing">  
   <result name="abc自定义(接受方法返回值)" type="dispatcher">  
   <param name="location">/views/jsp/index.jsp</param>  
   </result>  
   </action>  
   </package>   
   
 -->

注意:关于struts.xml文件的元素解释往下面找有解释。

注意:1、拷贝struts.xml文件到项目的source folder中(自定义resources)
         2、
<action name="b" class="clu.mochunrong.action.HellowAction" method="sing">这里的name不带斜杠“/”


访问Action:

           完整URL拆分 : 协议+主机地址+端口号+上下文路径+命名空间+资源名称

                                    http://localhost:80/crm/hello[.action]


--------------------------------------------------------------------------------------

注意:tomcat里面一定要设置好项目路径。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mc19

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值