使用js替代jsp中request.getParameter等方法

本文介绍了一个用于查询特定小区内基站话务量的网页应用。该应用支持GSM、TD和LTE三种类型的基站,并允许用户指定小区号、基站类型及查询时间范围。
‍<%@ page language="java"  contentType="text/html" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script type="text/javascript" src="${pageContext.request.contextPath}/common/js/jquery-1.4.4.min.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/common/js/mainJS.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/css/tablecss.css" />
<html>
  <head>
    <title>小区所属基站话务量</title>
    <script>
    function getArgs( ) {   
        var args = new Object( );   
        var query = location.search.substring(1);       
        var pairs = query.split("&");                    
        for(var i = 0; i < pairs.length; i++) {   
            var pos = pairs[i].indexOf('=');            
            if (pos == -1) continue;                     
            var argname = pairs[i].substring(0,pos);     
            var value = pairs[i].substring(pos+1);       
            value = decodeURIComponent(value);           
            args[argname] = value;                      
        }   
        return args;                                  
    } 
    
    <!--打开工单,赋默认值,查询数据-->
    window.onload=function(){
     var dcid = location.search.substring(1)
        $("#cellid").val(getArgs().cellid);
        $("#ntype").val(getArgs().ntype);
        $("#dualtime").val('5');
        asynsub();
    }   
    <!--返回数据处理-->
    function show(json){
     var tabledata = '';
     if( json.length==0||typeof(json)=="undefined" ){
      $("#showtable").html("<tr align='center'><td>无数据</td></tr>");
     }else{
      $("#showtable").html('');
      if($("#ntype").val()=="gsm"){
       tabledata+="<tr class='tabletitle'><td>序号</td><td>基站名称</td><td>基站号</td><td>小区名</td><td>小区号</td><td>话务量</td><td>时间</td></tr>";
      }else if($("#ntype").val()=="td"){
       tabledata+="<tr class='tabletitle'><td>序号</td><td>网元名称</td><td>NODEB号</td><td>小区名</td><td>小区号</td><td>话务量</td><td>时间</td></tr>";
      }else{
       tabledata+="<tr class='tabletitle'><td>序号</td><td>基站名称</td><td>NODEB号</td><td>小区名</td><td>小区号</td><td>话务量</td><td>时间</td></tr>";
      }
      for (var p in json) {
       var index = parseInt(p)+1;
       tabledata+="<tr class='tablecontent'>";
       tabledata+="<td align='center'>"+index+"</td>";
       tabledata+="<td align='center'>"+json[p].sitename+"</td>";
       tabledata+="<td align='center'>"+json[p].siteno+"</td>";
       tabledata+="<td align='center'>"+json[p].cellname+"</td>";
       tabledata+="<td align='center'>"+json[p].cellno+"</td>";
       tabledata+="<td align='center'>"+json[p].erl+"</td>";
       tabledata+="<td align='center'>"+json[p].datatime+"</td>";
       tabledata+="</tr>";
          }
      $("#showtable").append(tabledata);
     }
    }
    <!--通过ajax异步处理json数据请求-->
    function asynsub(){
     $("#loadmessage").html("<td style='color:blue'>正在查询告警库...</td>");
        $.ajax({ 
         type:"POST", //请求方式 
         ", //请求路径 
         cache: false,//浏览器缓存
         timeout:60000,//超时设置
         data:jsondata(), //传参 
         dataType: 'json',   //返回值类型 
         success:function(json,textStatus){  
          show(json);
          $("#loadmessage").html("<td style='color:green'>查询成功!</td>");
         },
    error: function(){
     $("#showtable").html("<tr align='center'><td>无数据</td></tr>");
     $("#loadmessage").html("<td style='color:red'>查询失败!</td>");
   }
        }); 
    }
    <!--传入参数处理-->
    function jsondata(){
     var jsonstr ="cellid="+$("#cellid").val();
     jsonstr+="&ntype="+$("#ntype").val();
     jsonstr+="&dualtime="+$("#dualtime").val();
     return jsonstr;
    }
    </script>
  </head>
  <script type="text/javascript">
  </script>
  <body>
  <div class="title">
   <img src="${pageContext.request.contextPath}/common/img/ico.gif">
   小区所属基站话务量
  </div>
  <form name="roleForm" method="post">
 <div id="searchdiv" >
 <table width="90%" align="center" class="searchtable" >
  <tr class="tabletitle">
   <td width="10%" >请输入查询小区号:</td>
   <td width="10%" >
    <input type="text" id="cellid"  title="温馨提示:若要查询多个小区号请用逗号隔开"  style="width:100%">
   </td>
   <td width="6%" > 
    <select  id="ntype" name="ntype" onchange="asynsub()"  style="width:100%">
     <option value="gsm"  selected>GSM站</option>
     <option value="td" >TD站</option>
     <option value="lte" >LTE站</option>
    </select>    
   </td>
   <td width="10%" >请选择时间范围:</td>
   <td width="6%" >
    <select  id="dualtime"  name="dualtime" onchange="asynsub()"  style="width:100%">
     <option value="5"  selected>5日以内</option>
     <option value="10" >10日以内</option>
     <option value="15" >15日以内</option>
    </select>
   </td>
   <td width="8%"><input class="button"  type="button" value="搜  索" onClick="asynsub()"></td>
   <td id="loadmessage"></td>
  </tr>
 </table>
 </div>
 <!-- 搜索结束-->
 <div id="showdiv">
 <table id='showtable' class='searchtable' align='center'>
 </table>
 </div> 
<!-- 
<input type="hidden" id="msg" name="msg"  />
<input type="hidden" value="" id="currentPage" name="currentPage">
<input type="hidden" value="" id="maxPage" name="maxPage">
 -->
</form>
</body>
</html>

 

转载于:https://my.oschina.net/GeminiLiu/blog/220345

5 应用系统的设计与实现 5.1 开发环境简介 本应用系统采用Java语言进行开发,基于B/S架构,使用JDBC作为数据访问接口,集成开发环境为Eclipse。前端采用HTML、CSS和JavaScript技术进行页面设计,后端使用Servlet和JSP技术实现业务逻辑和页面交互。 5.1 系统总体功能模块 系统主要有图书类别管理、出版社管理、图书管理、仓库信息管理、进货管理、入库管理、销售管理、出库管理等几个功能模块。功能模块图如图5-1所示。 图5-1 系统功能模块图 5.2 用户登录模块的设计实现 用户登录模块用于验证用户的身份,只有合法的用户才能进入系统。系统界面截图如图5-2所示。 图5-2 用户登录界面 关键代码如下: java @WebServlet("/login") public class LoginServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); if ("admin".equals(username) && "123456".equals(password)) { HttpSession session = request.getSession(); session.setAttribute("user", username); response.sendRedirect("index.jsp"); } else { request.setAttribute("error", "用户名或密码错误"); request.getRequestDispatcher("login.jsp").forward(request, response); } } } 5.3 图书管理模块的设计与实现 图书管理模块用于对图书的基本信息进行管理,包括查询、录入、删除、修改等操作。系统界面截图如图5-3所示。 图5-3 图书管理界面 关键代码如下: java // BookServlet.java @WebServlet("/book") public class BookServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); if ("list".equals(action)) { List<Book> books = BookDAO.getAllBooks(); request.setAttribute("books", books); request.getRequestDispatcher("book_list.jsp").forward(request, response); } else if ("add".equals(action)) { request.getRequestDispatcher("book_add.jsp").forward(request, response); } else if ("save".equals(action)) { String bookName = request.getParameter("bookName"); String author = request.getParameter("author"); String isbn = request.getParameter("isbn"); double price = Double.parseDouble(request.getParameter("price")); int categoryId = Integer.parseInt(request.getParameter("categoryId")); int publisherId = Integer.parseInt(request.getParameter("publisherId")); Book book = new Book(); book.setBookName(bookName); book.setAuthor(author); book.setIsbn(isbn); book.setPrice(price); book.setCategoryId(categoryId); book.setPublisherId(publisherId); BookDAO.addBook(book); response.sendRedirect("book?action=list"); } } } 使用C语言和mysql
最新发布
06-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值