国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

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

2024-09-01 08:27:13
字體:
供稿:網(wǎng)友

環(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提交到j(luò)ava后臺之后處理數(shù)據(jù)的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 濮阳县| 社旗县| 田林县| 蒙自县| 新闻| 济南市| 乌拉特中旗| 罗甸县| 天长市| 乌兰县| 奇台县| 青铜峡市| 河东区| 甘孜| 普定县| 长丰县| 奉贤区| 三亚市| 红桥区| 万宁市| 林芝县| 马龙县| 弥勒县| 甘泉县| 澄江县| 钦州市| 巴彦淖尔市| 徐州市| 祁连县| 永清县| 莫力| 茶陵县| 江陵县| 共和县| 兖州市| 阜南县| 讷河市| 讷河市| 宽城| 读书| 宽城|