struts2增删改查---layer---iframe层---通配符---国际化

在前一篇文章的基础上,修改一部分即可(在此只是简单介绍)

struts.xml页面

在原来的基础之上

action的name="*_*"  class="包名.{1}" method="{2}"

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 
 6 <struts>
 7  
 8  
 9  <!-- 国际化 -->
10  <constant name="struts.custom.i18n.resources" value="zr"></constant>
11 
12 <!-- user表的通配符增删改查 --> 
13  <package name="aa" namespace="/user"  extends="struts-default">
14   <action name="*_*"   class="com.zr.{1}"  method="{2}">
15     <result name="show">/show.jsp</result>
16     <result name="add" type="redirectAction">Struts2Text_showstuent?ye=1</result>
17     <result name="deletee" type="redirectAction">Struts2Text_showstuent?ye=1</result>
18     <result name="toupdate">/update.jsp</result>
19     <result name="update"  type="redirectAction">Struts2Text_showstuent?ye=1</result>
20   </action>
21  </package>
22  
23  <!-- class10表的通配符增删改查 -->
24   <package name="bb" namespace="/class"  extends="struts-default">
25   <action name="*_*"   class="com.zr.{1}"  method="{2}">
26     <result name="show">/Classshow.jsp</result>
27     <result name="add" type="redirectAction">ClassStruts2Text_showstuent?ye=1</result>
28     <result name="deletee" type="redirectAction">ClassStruts2Text_showstuent?ye=1</result>
29     <result name="toupdate">/Classupdate.jsp</result>
30     <result name="update"  type="redirectAction">ClassStruts2Text_showstuent?ye=1</result>
31   </action>
32  </package>
33 
34 </struts>

add.jsp页面

将原来的

 <form action="user/add.action" >   改为  

<form action="user/Struts2Text_add" >

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6  
 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 8 <html>
 9   <head>
10     <base href="<%=basePath%>">
11     
12     <title>My JSP 'add.jsp' starting page</title>
13     
14     <meta http-equiv="pragma" content="no-cache">
15     <meta http-equiv="cache-control" content="no-cache">
16     <meta http-equiv="expires" content="0">    
17     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
18     <meta http-equiv="description" content="This is my page">
19     <!--
20     <link rel="stylesheet" type="text/css" href="styles.css">
21     -->
22 
23     <script type="text/javascript" src="layer/layer.js"></script>
24     <script type="text/javascript">
25     function add(a){
26         a.submit();
27         var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
28         parent.ReloadData();
29         parent.layer.close(index); 
30         }
31     
32     </script>
33 
34 
35   </head>
36   
37   <body>
38  <form action="user/Struts2Text_add" >
39  <input type="hidden" name="id">
40  <input type="hidden" name="method" value="add">
41 <input type="text" name="username" placeholder=" 请输入姓名"><br/>
42 <input type="text" name="password" placeholder=" 请输入密码"><br/>
43  <input type="button" onclick="javascript:add(this.form)" value="确定添加"><br/>
44  </form>
45   </body>
46 </html>

index.jsp页面

对38以及39行代码进行修改

第二行为引入struts标签库   <s:  >  </s:  >

30-39行代码均有国际化的体现  也是与之前代码相比较修改的地方

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%@ taglib uri="/struts-tags" prefix="s" %>
 3 <%
 4 String path = request.getContextPath();
 5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 6 %>
 7 
 8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 9 <html>
10   <head>
11     <base href="<%=basePath%>">
12     
13     <title>My JSP 'index.jsp' starting page</title>
14     <meta http-equiv="pragma" content="no-cache">
15     <meta http-equiv="cache-control" content="no-cache">
16     <meta http-equiv="expires" content="0">    
17     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
18     <meta http-equiv="description" content="This is my page">
19     <!--
20     <link rel="stylesheet" type="text/css" href="styles.css">
21     -->
22     <STYLE type="text/css">
23     a{
24     text-decoration: none;
25     color: black;
26     }
27     </STYLE>
28   </head>
29   <body>
30   <s:text name="userName"></s:text> <input type="text" placeholder="请输入用户名"><br/>
31   <s:text name="password"></s:text> <input type="text" placeholder="请输入密码"><br/>
32   <s:text name="welcomeInfo">
33   <s:param>郭艺华</s:param>
34   <s:param>大哥</s:param>
35   </s:text>
36   <button> <s:text name="login"></s:text></button><br/>
37   ………………………………………………………………………………………………………………………………………………………………………………………………………<br/>
38   <a  href="user/Struts2Text_showstuent?ye=1"><s:text name="user"></s:text></a><br/>
39   <a  href="class/ClassStruts2Text_showstuent?ye=1"><s:text name="class"></s:text></a>
40   </body>
41 </html>

show.jsp页面

主要修改90-104行的分页代码   因为每一次翻页都需要用到show方法

也就是通配符的修改

  1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2 <%@ taglib  uri="http://java.sun.com/jsp/jstl/core"   prefix="c"%>
  3 
  4 <%
  5 String path = request.getContextPath();
  6 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  7 %>
  8 
  9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 10 <html>
 11   <head>
 12     <base href="<%=basePath%>">
 13     
 14     <title>My JSP 'show.jsp' starting page</title>
 15     
 16     <meta http-equiv="pragma" content="no-cache">
 17     <meta http-equiv="cache-control" content="no-cache">
 18     <meta http-equiv="expires" content="0">    
 19     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 20     <meta http-equiv="description" content="This is my page">
 21     <!--
 22     <link rel="stylesheet" type="text/css" href="styles.css">
 23     -->
 24     <script type="text/javascript" src="layer/jquery-1.8.2.min.js"></script>
 25     <script type="text/javascript" src="layer/layer.js"></script>
 26     <script type="text/javascript">
 27      function func10() {
 28             //iframe层
 29             layer.open({
 30                 type: 2,
 31                 title: 'layer mobile页',
 32                 closeBtn: 1, //不显示关闭按钮
 33                 shadeClose: true,
 34                 shade: 0.8,
 35                 area: ['380px', '90%'],
 36                 content: 'add.jsp' //iframe的url
 37             }); 
 38         }
 39 
 40      function func11(id) {
 41             //iframe层
 42             layer.open({
 43                 type: 2,
 44                 title: 'layer mobile页',
 45                 closeBtn: 1, //不显示关闭按钮
 46                 shadeClose: true,
 47                 shade: 0.8,
 48                 area: ['380px', '90%'],
 49                 content: 'user/Struts2Text_toupdate?id='+id //iframe的url
 50             }); 
 51         }
 52      
 53 
 54     function ReloadData(){
 55            window.location.reload();
 56          }
 57     </script>
 58     
 59     <style type="text/css">
 60         a{
 61         text-decoration: none;
 62         color: black;
 63         }
 64     </style>
 65     
 66     
 67   </head>
 68   
 69   <body>
 70            
 71              <table border="1" bordercolor="gray" >
 72              <tr>
 73               <th>编号</th>
 74                <th>姓名</th>
 75                <th>密码</th>
 76                  <th>删除</th>
 77                  <th>修改</th>
 78              </tr>
 79              <c:forEach items="${list}"  var="a">
 80              <tr>
 81               <td>${a.id}</td>
 82                <td>${a.username}</td>
 83                <td>${a.password}</td>
 84                <td> <a  href="user/Struts2Text_deletee?id=${a.id}">删除</a></td>
 85                <td> <a  href="javascript:func11(${a.id})">修改</a></td>
 86              </tr>
 87              </c:forEach>
 88              </table>
 89              
 90              <c:if test="${param.ye>1}">
 91              <a href="user/Struts2Text_showstuent?ye=1">首页</a>
 92              </c:if>
 93              <c:if test="${param.ye>1}">
 94              <a href="user/Struts2Text_showstuent?ye=${param.ye-1}">上一页</a>
 95              </c:if>
 96              <c:forEach begin="1" end="${count}" varStatus="a">
 97              <a href="user/Struts2Text_showstuent?ye=${a.index }">${a.index }</a>
 98              </c:forEach>
 99               <c:if test="${param.ye<count}">
100              <a href="user/Struts2Text_showstuent?ye=${param.ye+1}">下一页</a>
101              </c:if>
102              <c:if test="${param.ye<count}">
103              <a href="user/Struts2Text_showstuent?ye=${count}">尾页</a>
104              </c:if>
105              
106              
107            <a  href="javascript:func10()"> 添加 </a><br/>
108            
109            
110   </body>
111 </html>

然后是代码笔记,在这里就不放源代码了

关于通配符的(未国际化之前)

(通配符加国际化)

index.jsp页面

struts.xml文件配置   国际化  只需要加一句话

以下为properties文件  命名规范根据语言缩写来

具体可以在Internet选项进行查看

properties文件打开样式

以上就是简单的通配符以及国际化的简单介绍

仅供参考

仅供记录

2017-08-1020:23:24

请留下你的足迹...
原文地址:https://www.cnblogs.com/angelye/p/7341240.html