
【Related video recommendation:ajax video tutorial】
Environment: eclipse struts
The effect to be achieved:Click the button to submit the data to the background and then return to the front desk to display the data
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; } }
Related learning Recommended:java basic tutorial
The above is the detailed content of ajax submits to java background to process data. For more information, please follow other related articles on the PHP Chinese website!