热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

AJAX调用SERVLET的实例代码

工作需要自己写了个例子调用SERVLET的,可以运行,很简单就是一个index.jsp页面,一个GetAndPostExampleservlet后台,和WEB.XML配置文件index.jsp页面--------------------------------------------------------------

工作需要自己写了个例子调用SERVLET的,可以运行,

很简单就是一个index.jsp页面,一个GetAndPostExample servlet后台,和WEB.XML配置文件

index.jsp页面

-------------------------------------------------------------------------------------------------------


<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%request.setCharacterEncoding("GB2312");%>









  


    
     姓:


  


    


  


    生日:
  


  

 


  


    
 
  


  





-------------------------------------------------------------------------------------------------------

GetAndPostExample

-------------------------------------------------------------------------------------------------------


package temp;
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 GetAndPostExample extends HttpServlet {
        /**
         * Constructor of the object.
         */
        public GetAndPostExample() {
                super();
        }
        /**
         * Destruction of the servlet. 

         */
        public void destroy() {
                super.destroy(); // Just puts "destroy" string in log
                // Put your code here
        }
        /**
         * The doGet method of the servlet. 

         *
         * This method is called when a form has its tag value method equals to get.
         *
         * @param request
         *            the request send by the client to the server
         * @param response
         *            the response send by the server to the client
         * @throws ServletException
         *             if an error occurred
         * @throws IOException
         *             if an error occurred
         */
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                doPost(request, response);
        }
        /**
         * The doPost method of the servlet. 

         *
         * This method is called when a form has its tag value method equals to
         * post.
         *
         * @param request
         *            the request send by the client to the server
         * @param response
         *            the response send by the server to the client
         * @throws ServletException
         *             if an error occurred
         * @throws IOException
         *             if an error occurred
         */
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                String data = "";
                String temp = "";
                temp = (String) request.getParameter("firstName");
                data = data + "第一个名字" + temp;
                temp = (String) request.getParameter("middleName");
                data = data + "  中间的名字" + temp;
                temp = (String) request.getParameter("birthday");
                data = data + "  生日" + temp;
                temp = (String) request.getParameter("timeStamp");
                data = data + "  调用时间" + temp;
                System.out.println("获得的数据   " + data);
                response.setContentType("text/html;charset=gb2312");
                PrintWriter out = response.getWriter();
                out.println(data);
                out.flush();
                out.close();
        }
        /**
         * Initialization of the servlet. 

         *
         * @throws ServletException
         *             if an error occurs
         */
        public void init() throws ServletException {
                // Put your code here
        }
}


-------------------------------------------------------------------------------------------------------

web.xml

-------------------------------------------------------------------------------------------------------



        xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    GetAndPostExample
    temp.GetAndPostExample
  

  
    GetAndPostExample
    /GetAndPostExample
  

  
    index.jsp
  



-------------------------------------------------------------------------------------------------------


推荐阅读
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文介绍了一种处理AJAX操作授权过期的全局方式,以解决Asp.net MVC中Session过期异常的问题。同时还介绍了基于WebImage的图片上传工具类。详细内容请参考链接:https://www.cnblogs.com/starluck/p/8284949.html ... [详细]
  • Vue基础一、什么是Vue1.1概念Vue(读音vjuː,类似于view)是一套用于构建用户界面的渐进式JavaScript框架,与其它大型框架不 ... [详细]
  • Allegro总结:1.防焊层(SolderMask):又称绿油层,PCB非布线层,用于制成丝网印板,将不需要焊接的地方涂上防焊剂.在防焊层上预留的焊盘大小要比实际的焊盘大一些,其差值一般 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 禁止程序接收鼠标事件的工具_VNC Viewer for Mac(远程桌面工具)免费版
    VNCViewerforMac是一款运行在Mac平台上的远程桌面工具,vncviewermac版可以帮助您使用Mac的键盘和鼠标来控制远程计算机,操作简 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • 本文介绍了Svn和Maven的使用说明,包括版本控制和构建工具的功能和优势。同时提供了一个相关链接,链接中详细介绍了SvnMaven的使用方法和注意事项。通过学习和使用SvnMaven,开发人员可以更好地进行代码管理、软件开发和协作开发,提高项目管理的效率和质量。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • XMLhttpREquest_Ajax技术总结之XmlHttpRequest
    Ajax1、 什么是ajax   ... [详细]
author-avatar
278787061w
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有