struts2笔记1

web.xml配置

<!-- 配置struts2的中央控制器 -->
<filter>
  <!-- 取个名字叫struts2 -->
  <filter-name>struts2</filter-name>
  <!-- struts2中央控制器类的全路径 -->
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>struts2</filter-name>
  <!-- 当浏览器向服务器发送请求所对应的url,进行过滤(拦截*.action的请求) -->
  <url-pattern>*.action</url-pattern>
</filter-mapping>

 

 

struts.xml配置

<!-- 在src目录下创建struts2的核心配置文件 -->
<!-- web app libraries/struts2-core-2.3.24.jar/struts-2.1.dtd(30-32行复制过来)-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">

 

<struts>

  <!-- 配置struts2服务器编码为GBK,name值在org.apache.struts2/default.properties(29行)-->
  <constant name="struts.i18n.encoding" value="GBK"></constant>

 

  <!-- name值在 org.apache.struts2/default.properties(109行,不同版本不一定在109行)-->
  <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>


  <package name="struts2" extends="struts-default">
    <!-- 注册自定义Action -->
    

    <!-- <action name="userAction_query" class="com.test.struts2.action.UserManagerAction" method="query">
      <result name="query">/query.jsp</result>
    </action>
    <action name="userAction_save" class="com.test.struts2.action.UserManagerAction" method="save">
      <result name="save">/save.jsp</result>
    </action>
    <action name="userAction_update" class="com.test.struts2.action.UserManagerAction" method="update">
      <result name="update">/update.jsp</result>
    </action>
    <action name="userAction_delete" class="com.test.struts2.action.UserManagerAction" method="delete">
      <result name="delete">/delete.jsp</result>
    </action> -->




    <!-- Action中动态方法调用 -->
    <!-- http://localhost:8080/struts2_02_deep/userAction!delete.action -->
    <!-- <action name="userAction" class="com.test.struts2.action.UserManagerAction">
        <result name="query">/query.jsp</result>
        <result name="save">/save.jsp</result>
        <result name="update">/update.jsp</result>
        <result name="delete">/delete.jsp</result>
    </action> -->




    <!-- 通配符方式动态调用 -->
    <!-- http://localhost:8080/struts2_02_deep/userAction_save.action -->
    <action name="userAction_*" class="com.test.struts2.action.UserManagerAction" method="{1}">
      <result name="{1}">/{1}.jsp</result>
    </action>


    <action name="apiAction" class="com.test.struts2.action.ApiAction" method="getApi">
      <result name="api">/api.jsp</result>
    </action>


  </package>
</struts>

 

页面引入struts2标签库

<%@taglib prefix="s" uri="/struts-tags" %>

 

 

spring mvc+hibernate

https://blog.csdn.net/mr_orange_klj/article/details/78643442

posted @ 2018-05-13 13:16  nike_ha  阅读(129)  评论(0编辑  收藏  举报