这个是jsp页面
<%@ page contentType="text/html; charset=utf-8"%>
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"></head>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<head>
<sx:head/>
</head>
<sx:div
href="ajaxServerAction.action"
showLoadingText="true"
loadingText="正在加载内容,请稍候"
errorText="对不起,加载资源失败,请重试"
>
</sx:div>
然后是srtuts.xml
<action name="ajaxServerAction" class="com.yuan.struts2.action.AjaxServerAction">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
接着是action
package com.yuan.struts2.action;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import com.opensymphony.xwork2.ActionSupport;
public class AjaxServerAction extends ActionSupport {
private InputStream inputStream;
public InputStream getInputStream() {
return inputStream;
}
public String execute() throws Exception {
Thread.sleep(3000L);
inputStream = new ByteArrayInputStream("这是一个div的测试".getBytes("utf-8"));
return SUCCESS;
}
}
很简单的一个示例,可是网页报错,div不显示文字
Uncaught TypeError: Cannot read property '0' of null localhost:8080/Struts2-helloWorld/struts/dojo/struts_dojo.js:36
Uncaught TypeError: undefined is not a function localhost:8080/Struts2-helloWorld/struts/ajax/dojoRequire.js:22
Uncaught TypeError: Cannot read property 'push' of undefined localhost:8080/Struts2-helloWorld/ajax.jsp:34