zoukankan      html  css  js  c++  java
  • 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);
        }
    
        
    
    }

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

  • 相关阅读:
    html的URL参数传值问题
    html背景图片拉伸至全屏
    Laravel 用户验证Auth::attempt fail的问题
    HTML中meta的应用
    ubuntu升级php版本
    Laravel 目录结构分析
    css颜色渐变在不同浏览器的设置
    谷歌浏览器(Chrome)离线包的下载方法!
    RAD Studio 10 up1欢迎页证书不可用
    MySQL
  • 原文地址:https://www.cnblogs.com/sunxiaoyan/p/8873344.html
Copyright © 2011-2022 走看看