实现预览功能时遇到的小问题?
各位,大家好!
请教大家个问题,希望能给我点帮助!谢谢先!
问题是这样的:
想实现个预览功能,就是点“预览”后,弹出一个新窗口,将后台传过来的一个字符串在这个新窗口中给显示出来。
现在已经实现了部分功能,就是点“预览”后,能在当前页把后台传过来的一个字符串给显示出来,可是如何在新窗口显示呢?请各位给点意见。谢谢!
部分代码如下:
jsp页面代码:
……
<script type="text/javascript">
<!--
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
function preview(actId) {
var url = "activity/actPreview.do?actId="+escape(actId);
request.open("GET", url, true);
request.onreadystatechange =
function(){
if (request.readyState == 4)
if (request.status == 200){
var data = request.responseText;
document.write(data);
}
else if (request.status == 404)
alert("Request URL does not exist");
else
alert("Error: status code is " + request.status);
};
request.send(null);
}
//-->
</script>
……
<a href='javascript:preview(${actId})'>预览 </a>
……
action中部分代码:
public ActionForward actPreview(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter out = response.getWriter();
String actId = request.getParameter("actId");
System.out.println("=========actId = "+actId+"===============");
out.println
(" <html> <body> <table> <tr> <td>aaa </td> <td>bbb </td> </tr> <tr> <td>ccc </td> <td>ddd </td> </tr> </table> </body> </html>");
out.flush();
out.close();
return null;
}
------解决方案--------------------用window.open('aa.jsp?a=返回的数据');
作为参数带过去 。。在那边用<%String a=request.getParameter("a"); %>获得
------解决方案--------------------用window.open('aa.jsp?a=返回的数据');
作为参数带过去 。。在那边用 <%String a=request.getParameter("a"); %>获得