最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ajax提交到java后臺之后處理數(shù)據(jù)的實現(xiàn)

 更新時間:2017年05月24日 09:11:01   投稿:jingxian  
下面小編就為大家?guī)硪黄猘jax提交到java后臺之后處理數(shù)據(jù)的實現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

環(huán)境:eclipse+struts

要實現(xiàn)的效果:點擊按鈕提交數(shù)據(jù)到后臺之后回到前臺顯示出來數(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提交到java后臺之后處理數(shù)據(jù)的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論

新和县| 博客| 越西县| 安溪县| 陇南市| 乌拉特中旗| 天等县| 石林| 竹山县| 红原县| 姚安县| 香港 | 陵水| 大埔县| 龙川县| 宁远县| 荣昌县| 潮安县| 定陶县| 绍兴市| 开原市| 布尔津县| 资溪县| 张家界市| 巴南区| 西平县| 福建省| 穆棱市| 台东县| 德格县| 本溪市| 巫山县| 北票市| 铜梁县| 建平县| 保康县| 武功县| 漠河县| 澄城县| 正镶白旗| 澄迈县|