struts2 的一个简单配置

 

1.首先从start.jsp页面开始跳转

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'start.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
     <jsp:forward page="accountAction.action?method=getAll" />
  </body>
</html>


2.然后交给一个action进行处理

 

web.xml的配置文件

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
 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_3_0.xsd">
  <display-name></display-name> 
 
  <filter>
     <filter-name>struts</filter-name>
     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
     <filter-name>struts</filter-name>
     <url-pattern>/*</url-pattern>
     <dispatcher>REQUEST</dispatcher>                              <!--因为start.jsp页面红包含转发,所以需要配置这个属性-->
     <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

  <welcome-file-list>
    <welcome-file>start.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

3.<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- 指定全局国际化资源文件 -->
<struts>
 
  <!-- 指定国际化编码的字符集 -->
  <constant name="struts.i18n.encoding" value="GBK" />
 
  <!-- 所有的Action定义都应该放在package下 -->
 <package name="lee" extends="struts-default">
  <action name="accountAction" class="com.strutsT5.action.AccountAction">
   <!-- 定义三个逻辑视图和物理资源之间的映射 -->  
   <result name="index">/index.jsp</result>
  </action>
 </package>
</struts>

 

3.然后显示页面

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
     
    <title>My JSP 'index.jsp' starting page</title>
    <style type="text/css">
       
    </style>
    
    <script type="text/javascript">
       
       function fillValue(state,id){
       
          if(state==0){
              alert("该会员已经禁用,不能充值!");
          }else{
              window.open("fillValue.jsp?id="+id,"","width=260px,height=120px");
          }
       }
    </script>
  </head>
  
  <body>
     <table width="400px" height="62px" border="0px" align="left" cellpadding="0px" cellspacing="2">
         <tr>
             <td width="400px" height="28px" nowrap="nowrap">
                 <table width="100%" border="1px" cellpadding="2" cellspacing="0"  bordercolorlight="#ffffff" bordercolordark="#003399">
                    <tr align="center" bgcolor="#396796">
                        <td width="100%" height="33px" align="right">
                                <span> ********会员账户管理系统******</span>
                                <select name="state" id="cmbState" style="width:100px" οnchange="window.location='accountAction.action?action=getAll&state='+this.value">
                                     <option value="-1" selected="selected">全部</option>
                                     <option value="0">禁用</option>
                                     <option value="1">启用</option>
                                </select>
                        </td>
                    </tr>
                 </table>
             </td>
         </tr>   
         <tr>
             <td height="28px" nowrap="nowrap">
                 <table width="100%" border="1px" align="center" cellpadding="5" cellspacing="0" bgcolor="#D0D0D5" style="border-collapse: collapse;">
                       <tr style="background-color:gray;" align="center" bgcolor="#	E7E7EF">
                           <td height="18" nowrap="nowrap">用户名</td>
                           <td>密码</td>
                           <td>余额</td>
                           <td>操作</td>
                       </tr>
                       <c:forEach items="${accountList }"  var="row">
	                       <tr align="center" bgcolor="#F7F6FB">
	                             <td nowrap="nowrap">${row.userId }</td>
	                             <td nowrap="nowrap">${row.realName }</td>
	                             <td nowrap="nowrap">${row.balance}</td>
	                             <td nowrap="nowrap">
	                                    <c:if test="${row.state == 0 }">
	                                           <a href="accountAction.action?action=setState&state=1&id=${row.id }" >禁用</a>
	                                    </c:if>
	                                    <c:if test="${row.state == 1 }">
	                                           <a href="accountAction.action?action=setState&state=0&id=${row.id }"> 启用</a>
	                                    </c:if>
	                                    <a href="accountAction.action?action=delAccount&id=${row.id }" οnclick="return confirm('确认要删除吗?');">删除</a>  
	                                    <a href="javascript:void(0)" οnclick="fillValue(${row.state},${row.id })">充值</a>
	                             </td>
	                       </tr>   
                      </c:forEach>
                 </table>
             </td>
         </tr>        
     </table>
      <script type="text/javascript">
         //document.getElementById("cmbState").value=${param.state};
      </script>
  </body>
</html>


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值