ajax提交到j(luò)ava后臺(tái)之后處理數(shù)據(jù)的實(shí)現(xiàn)
環(huán)境:eclipse+struts
要實(shí)現(xiàn)的效果:點(diǎn)擊按鈕提交數(shù)據(jù)到后臺(tái)之后回到前臺(tái)顯示出來(lái)數(shù)據(jù)
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<input type="text" id="userinput">
<input type="button" id="submit">
<div id="msg"></div>
</body>
<script type="text/javascript" src="jquery-2.1.0.js"></script>
<script type="text/javascript">
window.onload = function() {
document.getElementById("submit").onclick = test;
}
function test(){
var userinput = document.getElementById("userinput");
$.post("http://localhost:8080/TestSpring/TestAction",{username:userinput.value},
function(data, textStatus){
document.getElementById("msg").innerHTML = data;
});
}
</script>
</html>
struts.xml
<action name="TestAction" class="com.action.Test"> <result>index.jsp</result> </action>
Test.java
package com.action;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class Test extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
HttpServletRequest request = org.apache.struts2.ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
out.write(request.getParameter("username"));
out.flush();
out.close();
return SUCCESS;
}
}
以上這篇ajax提交到j(luò)ava后臺(tái)之后處理數(shù)據(jù)的實(shí)現(xiàn)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- jQuery+datatables插件實(shí)現(xiàn)ajax加載數(shù)據(jù)與增刪改查功能示例
- MVC+jQuery.Ajax異步實(shí)現(xiàn)增刪改查和分頁(yè)
- jQuery的Ajax接收java返回?cái)?shù)據(jù)方法
- ajax java 實(shí)現(xiàn)自動(dòng)完成功能
- AJAX+JAVA用戶登陸注冊(cè)驗(yàn)證的實(shí)現(xiàn)代碼
- 詳解Java Ajax jsonp 跨域請(qǐng)求
- Java使用Ajax實(shí)現(xiàn)跨域上傳圖片功能
- Javaweb使用cors完成跨域ajax數(shù)據(jù)交互
- 深入Ajax代理的Java Servlet的實(shí)現(xiàn)詳解
- 在Java的Struts中判斷是否調(diào)用AJAX及用攔截器對(duì)其優(yōu)化
- AJAX實(shí)現(xiàn)數(shù)據(jù)的增刪改查操作詳解【java后臺(tái)】
相關(guān)文章
服務(wù)端配置實(shí)現(xiàn)AJAX跨域請(qǐng)求
這篇文章主要介紹了服務(wù)端配置實(shí)現(xiàn)AJAX跨域請(qǐng)求的相關(guān)資料,需要的朋友可以參考下2015-02-02
Ajax實(shí)現(xiàn)動(dòng)態(tài)加載組合框的實(shí)例代碼
本文通過(guò)實(shí)例代碼給大家介紹了Ajax實(shí)現(xiàn)動(dòng)態(tài)加載組合框功能,感興趣的朋友一起看看吧2017-08-08
AngularJS tab欄實(shí)現(xiàn)和mvc小案例實(shí)例詳解
這篇文章主要介紹了angularJS tab欄實(shí)現(xiàn)和mvc小案例,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2017-05-05
JQuery+Ajax+Struts2+Hibernate框架整合實(shí)現(xiàn)完整的登錄注冊(cè)
最近沒(méi)有項(xiàng)目做,閑著沒(méi)事,看到一個(gè)書城的網(wǎng)站很好,于是就是仿了一個(gè),把里面的ui直接拿過(guò)來(lái)用,前端后端自己寫的,目前大部分的功能已經(jīng)實(shí)現(xiàn)了。2015-10-10
使用AJAX異步通信技術(shù)實(shí)現(xiàn)搜索聯(lián)想和自動(dòng)補(bǔ)全示例
這篇文章主要介紹了使用AJAX異步通信技術(shù)實(shí)現(xiàn)搜索聯(lián)想和自動(dòng)補(bǔ)全示例,AJAX是前后臺(tái)交互的能? 也就是我們客戶端給服務(wù)端發(fā)送消息的?具,以及接受響應(yīng)的?具,需要的朋友可以參考下2023-05-05
淺談Ajax相關(guān)及其優(yōu)缺點(diǎn)
最近在學(xué)習(xí)有關(guān) AJAX 的知識(shí),上網(wǎng)查閱了一些有關(guān) AJAX 的資料,主要是有關(guān) AJAX的技術(shù)簡(jiǎn)介及其優(yōu)缺點(diǎn)等。在這里,我想對(duì)我收集的資料做一些小小的總結(jié),大部分資料都來(lái)自網(wǎng)上,本人在此只做分類總結(jié),希望對(duì)和我一樣正在學(xué)習(xí) AJAX 的朋友有一定的幫助。2015-06-06
通過(guò)構(gòu)造AJAX參數(shù)實(shí)現(xiàn)表單元素JSON相互轉(zhuǎn)換
這篇文章主要介紹了通過(guò)構(gòu)造AJAX參數(shù)實(shí)現(xiàn)表單元素JSON相互轉(zhuǎn)換 的相關(guān)介紹,需要的朋友可以參考下2016-05-05

