zoukankan      html  css  js  c++  java
  • 案例

    1、加载jar包
     
    2、搭建环境
    配置struts2核心控制器web.xml
     
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>_struts2_4s</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      <!-- 配置struts2核心控制器 -->
      <filter>
               <filter-name>struts2</filter-name>
              <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>
     
      <filter-mapping>
               <filter-name>strut2</filter-name>
               <url-pattern>/*</url-pattern>
      </filter-mapping>
    </web-app>
     
    配置struts.xml
     
    3.写Action,配置
     
    struts.xml
    <struts>
         <!-- 常量配置 -->
         <constant name="struts.i18n.encoding" value="utf-8"></constant>
         <constant name="struts.action.extension" value="action,do,"></constant>
         <!-- 当前框架处于开发状态,易于调试。上线时改为false -->
         <constant name="struts.devMode" value="true"></constant>
     
         <include file="struts-*.xml"></include>
     
         <!-- 项目基础包 -->
         <package name="base" extends="struts-default" >
     
                    <interceptors>
                         <!-- 定义拦截器 -->
                         <interceptor name="mylg" class="com.it.intercp.MyLogger"></interceptor>
                         <!-- 定义拦截器栈-->
                         <interceptor-stack name="tk">
                               <interceptor-ref name="defaultStack"></interceptor-ref>
                               <interceptor-ref name="mylg"></interceptor-ref>
                         </interceptor-stack>
                    </interceptors>
     
         </package>
     
    </struts>
     
    syruts-user.xml
         <!-- 建立用户业务逻辑包 -->
         <package name="userLogic" namespace="/users" extends="base">
               <!-- 定义一拦截器 -->
               <default-interceptor-ref name="tk"></default-interceptor-ref>
               <!-- 添加Action -->
               <action name="add" class="com.it.action.UserOptAction" method="addUser">
                    <result name="ok" type="chain">show</result>
                    <!-- 令牌拦截器,防止重复提交 -->
                    <result name="invalid.token" type="redirect">/users/x.html</result>
               </action>
     
               <!-- 删除Action -->
               <action name="del" class="com.it.action.UserOptAction" method="delUser">
                    <result name="ok" type="chain">show</result>
               </action>
     
               <!-- 修改Action -->
               <action name="upd" class="com.it.action.UserOptAction" method="updUser">
                    <result name="ok" type="chain">show</result>
               </action>
     
               <!-- 查询一个User,Action -->
               <action name="findOne" class="com.it.action.UserFindAction"  method="findOne" >
                    <result name="ok">/users/upd.jsp</result>
               </action>
     
         <!-- 查看全部Action -->
               <action name="show" class="com.it.action.UserFindAction" method="findUser">
                    <result name="ok">/users/show.jsp</result>
               </action>
     
         </package>
    </struts>
     
     
    add,jsp:
     
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@taglib uri="/struts-tags" prefix="s" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>add</title>
    </head>
    <body>
    <s:form namespace="/users" action="add">   <!-- strust标签 -->
     
         <s:textfield name="user.user_id"></s:textfield>
         <s:textfield name="user.user_pwd"></s:textfield>
         <s:textfield name="user.user_sex"></s:textfield>
         <s:token></s:token>
         <s:submit></s:submit>
     
    </s:form>
    </body>
    </html>
  • 相关阅读:
    再理解HDFS的存储机制
    C实现头插法和尾插法来构建单链表(不带头结点)
    linux系统编程:线程同步-相互排斥量(mutex)
    基于github for windows&amp;github的团队协作基本操作
    分治法求众数问题 (配图)
    hdu1576 mod 运算的逆元
    Android5.0(lollipop)新特性介绍(一)
    jenkins详解(一)
    手机APP测试点总结
    App测试方法总结
  • 原文地址:https://www.cnblogs.com/nin-w/p/5907495.html
Copyright © 2011-2022 走看看