<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'index.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">
-->
<script type="text/javascript" src="jquery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
function subTest(){
$.post("DoIndex", { name: "John", time: "2pm" },
function(data){
$("#test").html(data);
});
}
</script>
</head>
<body>
<input type="button" name="测试" value="测试" onclick="subTest()"></input>
<h1 id="test"></h1>
</body>
</html>
servlet中的写法
package com.dragon.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 DoIndex extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public DoIndex() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* 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 {
//response.setContentType("text/html");
//PrintWriter out = response.getWriter();
//out
//.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
//out.println("<HTML>");
//out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
//out.println(" <BODY>");
//out.print(" This is ");
//out.print(this.getClass());
//out.println(", using the GET method");
//out.println(" </BODY>");
//out.println("</HTML>");
//out.flush();
//out.close();
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* 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 {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("数据查询成功!");
//out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
//out.println("<HTML>");
//out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
//out.println(" <BODY>");
//out.print(" This is ");
//out.print(this.getClass());
//out.println(", using the POST method");
//out.println(" </BODY>");
//out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
本人亲测成功
如图
调用前:
调用后:
相关推荐
在JQuery中可以使用get,post和ajax方法给服务器端传递数据 get方法的使用(customForGet.js文件): function verify(){//1.获取文本框的数据 //通过DOM的方式获取//document.getElementByIdx(“userName”);//通过...
在 jsp 中处理 JSON,通常需要配套使用 JQuery 控件,并且导入一些 Common jar 包。 使用 JQuery 控件是因为它能有效的解析并且展示 JSON 数据, 导入Common 则是因为 Java 中的对象并不是纯粹的数据,需要通过...
jquery 异步提交的例子。使用的是jquery + servlet 。使用jquery $.get() $.post() 提交请求道servlet 页面
jquery实现数据动态加载分页的完整版,不错哦,欢迎下载
以前在新浪博客写过js调用AJAX时Get和post的乱码解决办法,但是使用js代码比较繁琐,我们在使用ajax进行数据交互时可以使用js的一个成熟框架—jQuery。 一个网站的设计,不管是注册登录还是分页查找,都需要提交参数...
项目内容从创建原生态的HTTPXMLRequest实现ajax开始,详细讲解ajax的应用,各种应用场合的实战案例;利用JQuery的ajax支持,...7.使用JQuery的ajax技术,在一个页面实现新增、修改、删除、查询、分页,文件上传等功能;
去掉servlet中下面这一句代码即可解决问题: 二.使用jquery发送带中文参数数据的get请求得到响应数据乱码 get: post: 执行过程: 使用jquery发送post和get请求时,请求端和响应端均设置了编码,为
本文实例讲述了jQuery解析返回的xml和json方法。分享给大家供大家参考,具体如下: 一、jQuery 解析ajax请求返回的xml格式的数据 1、发送ajax请求 [removed] function jqxml(){ $.ajax({ url:...
注意:在Post方式时,param1和param2为向远程发送的参数值,可以有多个。 代码如下://GET方式function reqeustCrossDomainProxyGet(){ var url = “http://www.baidu.com”;//远程请求地址 var param = {...
这里使用servlet的方式 1、采用$.post方法 index.jsp页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@ page ...
在管理list.jsp页面直接使用响应的HTML片段 6.请求路径: http://localhost:9999/java6_chapter912_ajax_jquery3/ajaxtest_base.jsp http://localhost:9999/java6_chapter912_ajax_jquery3/login.jsp ...
Jquery自动补全1.servlet中 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String word = request.getParameter("word"); request....
jqyery ajax $.ajax $.post 两种方式 此例子,分别用了两种处理方式实现, 用tomcat6.0 servlet jsp 调试很方便 下载解压后 直接用myeclipse导入,就可以调试,没有用数据库,适合新手学习。 如果调试不成功的,...
后端:`JavaEE`,`servlet`(创建servlet,使用get和post请求处理数据;使用Request,Response,session存储数据),`JDBC`(德鲁伊数据库连接池,使用QueryRunner处理数据) 和上一次系统[bootstrap+JavaEE+JDBC+JSP的...
Servlet&JSP&Ajax&JSON&jQuery1 架构: ...4 web xml的模板 一个web xml中可以配置多个Servlet : 5 tomcat的安装: 6 Servlet的运行过程(重点): 7 http协议 了解 : 8 get post请求:
10、servlet中怎么定义forward 和redirect 35 11、过滤器有哪些作用? 35 12、JSP的常用指令? 35 13、JSP和Servlet中的请求转发分别如何实现? 35 14、JSP乱码如何解决? 36 15、session 和 application的区别? 36...
Java面试题19.Servlet中forward和redirect的区别 Java面试题20.jsp和Servlet的相同点和不同点 Java面试题21.内置对象和四大作用域和页面传值 Java面试题22.Session和Cookie的区别和使用场景 Java面试题23.mvc模式和...
76.4. 在weblogic管理制台中对一个应用域(或者说是一个网站,Domain)进行jms及ejb或连接池等相关信息进行配置后,实际保存在什么文件中? 86 76.5. 在weblogic中发布ejb需涉及到哪些配置文件 87 76.6. 如何在weblogic中...