• Jquery中的ajax应用(第九章PPT)


    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'adjx.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">
        <script type="text/javascript" src="js/jquery-3.3.1.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#submit").click(function(){
                    var param = {
                        name:$("#name").val(),
                        age:$("#age").val()
                    };
                    $.ajax({
                        data:param,
                        url:"oneServlet",
                        beforeSend:function(){
                            $("img").show();
                        },
                        complete:function(){
                            $("img").hide();
                        },
                        success:function(data){
                            alert(data);
                        },
                        error:function(XMLHttpRequest, textStatus, errorThrown){
                            alert(XMLHttpRequest.status+" "+textStatus+" "+errorThrown);
                        }
                        
                    });
                    
                });
            });
        </script>
      </head>
    
      <body>
      <form>
           <table>
               <tr><td>name:</td><td><input type="text" id="name" name="name"></td></tr>
               <tr><td>age:</td><td><input type="text" id="age" name="age"></td></tr>      
               <tr><td><input type="button" value="submit" id="submit"></td></tr>      
           </table>
           <img src="images/6.jpg">
           </form>
      </body>
    </html>

    servlet:

    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    
    public class oneServlet extends HttpServlet {
    
        
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            String name = request.getParameter("name");
            String age = request.getParameter("age");
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.print(name+":"+age);
            
        }
    
    
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
                doGet(request, response);
        }
    
        
    
    }

    ************************************************************************************************************************************************************************************************

  • 相关阅读:
    Seminar Schedule
    数学建模之Python操作csv文件
    Pandas之csv文件对列行的相关操作
    Python之文件读写(csv文件,CSV库,Pandas库)
    PATA1028 List Sorting
    19.8.9(全局变量和局部变量的作用域)
    PATA1012The Best Rank(25分)
    DEV-gridview导出Excel
    WPF文本换行
    下拉框--可多选
  • 原文地址:https://www.cnblogs.com/sunxiaoyan/p/8873344.html
Copyright © 2020-2023  润新知