下面小编就为大家带来一篇ajax提交到java后台之后处理数据的实现。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
环境:eclipse+struts
要实现的效果:点击按钮提交数据到后台之后回到前台显示出来数据
index.jsp
< page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"Insert title here
struts.xml
index.jsp
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后台之后处理数据的实现的详细内容,更多请关注易知道|edz.cc其它相关文章!