jsp使用jquery通过ajax方式访问servlet
来源:互联网 发布:linux java cpu占用高 编辑:程序博客网 时间:2024/06/05 08:44
摘自:http://hi.baidu.com/mengxingle_13/blog/item/358c4319c3994abe4bedbce2.html【jquery $.ajax({})例子 java】
<title>My JSP 'index.jsp' starting page</title>
$.ajax({ type:"post",//请求方式 url:"./test",//发送请求地址 data:{//发送给数据库的数据 username:$("#username").val(), content:$("#content").val() }, //请求成功后的回调函数有两个参数 success:function(data,textStatus){ $("#resText").html(data); } });
</script>
throws ServletException, IOException { //处理中文问题 request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); System.out.println("start............"); String username=request.getParameter("username"); String content=request.getParameter("content"); //username=new String(username.getBytes("gb2312"),"utf-8"); PrintWriter out = response.getWriter(); out.write(username); System.out.println("username>>=="+username); out.write(content); out.flush(); out.close(); System.out.println("end");
jsp
<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content" content="text/html;charset=utf-8">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
function sub()
{
}
</head>
<body>
<form action="./test" id="form1" method="post">
<p>评论:</p>
<p>姓名:<input type="text" name="username" id="username"/></p>
<p>内容:<textarea name="content" id="content" rows="2" cols="20"></textarea></p>
<p><input type="button" id="send" value="提交" onclick="sub();"/></p>
</form>
<div class="comment">
已有评论:
</div>
<div id="resText">
</div>
</body>
</html>
java代码
package com;
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 test extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
}
}
- jsp使用jquery通过ajax方式访问servlet
- jsp使用jquery通过ajax方式访问servlet
- jsp使用jquery通过ajax方式访问servlet
- jsp使用jquery通过ajax方式访问servlet
- jsp使用jquery通过ajax方式访问servlet
- jsp使用jquery通过ajax方式访问
- JQuery Ajax Jsp Servlet组合
- Jquery Ajax(jsp Servlet)
- Jsp servlet+jquery+ajax实现
- 使用Jsp/Js/Ajax/Json/Jquery/Easyui + Servlet + JDBC + Lucen
- Jquery Ajax方式访问WebService
- JSP+JQuery Ajax+Servlet 实现轮询方式消息提示功能
- Jquery ajax 访问Servlet 处理 Json 数据
- Jquery ajax 访问Servlet 处理 Json 数据
- jsp访问servlet类几种方式的写法
- 跨域访问:jquery ajax jsonp的实现方法(jsp和action方式)
- jQuery ajax 通过get方式实现
- Jquery通过Ajax方式提交Form表单
- ruby打开共享文件夹里面的类容
- Perl 内置特殊变量
- cocos2d-x与CocosBuilder笔记:HelloCocosBuilder
- cocos2d-x 字体描边CCRenderTexture glBlendFunc
- 基于jquery和php实现AJAX长轮询(LongPoll)
- jsp使用jquery通过ajax方式访问servlet
- 股票问题
- Best Practices for Scaling the Windows Forms DataGridView Control(winform中控制DataGridView控件规模的最佳实践)
- Linux-Unix比较牛B的认证有哪些?
- ddcms的一个bug(php版本不兼容问题)
- 游戏开发技术总结(经典之作)第二集 游戏我来了----BMP图形的调入和显示方法
- C++ 继承中的隐藏与覆盖祥解
- 为什么C++编译器不能支持对模板的分离式编译
- 去除FireFox中点击链接的时候,出现的虚线的边框框