涉及
Struts.xml、return "success"、return null、request.getWrite().write(str)
Ajax、success: function(data){}
关于 request.getWrite().write(s)
package com.ikoo; import java.io.IOException; import java.io.PrintWriter;// java.io import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext;// struts2 import org.junit.Test; public class TestWrite { @Test public void test(String s) { HttpServletResponse response = ServletActionContext.getResponse();// 这里用的Struts2 response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); try { PrintWriter printWriter = response.getWriter(); printWriter.write(s); // response.getWriter().write(s); // 作用:直接向客户端页面返回数据(将数据直接写到客户端页面上) } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
时间: 2024-11-05 21:53:25