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

ajax提交到j(luò)ava后臺(tái)之后處理數(shù)據(jù)的實(shí)現(xiàn)

 更新時(shí)間:2017年05月24日 09:11:01   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇ajax提交到j(luò)ava后臺(tái)之后處理數(shù)據(jù)的實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

環(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è)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

桂东县| 广州市| 成安县| 常宁市| 汝城县| 新晃| 花莲市| 海林市| 栾川县| 北安市| 神木县| 凌云县| 德化县| 和硕县| 蕲春县| 海兴县| 尤溪县| 涪陵区| 房产| 湖北省| 宁武县| 额敏县| 象山县| 前郭尔| 江阴市| 政和县| 上饶市| 太康县| 云安县| 甘孜县| 尉犁县| 青河县| 靖边县| 吴川市| 江安县| 龙门县| 筠连县| 海阳市| 丽水市| 金坛市| 中牟县|