Implementation of Data Processing after ajax is submitted to the java background, ajaxjava
Environment: eclipse + struts
Effect:Click the button to submit the data to the background and return to the foreground to display the data.
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">
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; } }
After the above ajax is submitted to the java background, the implementation of data processing is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.