日期:2014-05-16  浏览次数:20541 次

Iframe的异步功能返回响应问题?
有个表单,点击提交target发送到一个隐藏的Iframe,action发送到servlet
servlet有个out.write( "OK ");

现在想取得servlet的响应值 "OK ",怎么得到.这个响应是发送到Iframe里了么?
怎么让主页面得到


------解决方案--------------------
在你的servlet输出中加上js代码啊.
String Msg= " <script> ";
Msg+= "var control=parent.getElementById( 'xxxx '); "//获取你要操作的控件
Msg+= "control=xxxxxxx ";//操作你的控件
Msg+= " </script> ";
out.write(Msg);
------解决方案--------------------
'ok '直接在就在Iframe中显示了
1---------------------------------------
写个jsp页面:
<%@ page contentType= "text/html; charset=GBK " %>
<html>
<head>
<title>
index
</title>
</head>
<body bgcolor= "#ffffff ">
<iframe width=420 height=330 name=aa frameborder=1 > </iframe>
<form action= "sentok " target= "aa ">
<input type= "submit " />
</form>
</iframe>
</body>
</html>
2-----------------------------------------------------
写个servlet页面:SentOk.java
package com.test;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class SentOk extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK ";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println( " <html> ");
out.println( " <head> <title> SentOk </title> </head> ");
out.println( " <body bgcolor=\ "#ffffff\ "> ");
out.println( " <p> The servlet has received a " + request.getMethod() + ". This is the reply. </p> ");
out.println( "ok! ");
out.println( " </body> </html> ");
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}
3-----------------------------------------web.xml--------
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN " "http://java.sun.com/dtd/web-app_2_3.dtd ">
<web-app>
<display-name> webTest </display-name>
<servlet>
<servlet-name> sentok </servlet-name>
<servlet-class> com.test.SentOk </servlet-class>
</servlet>
<servlet>
<servlet-name> debugjsp </servlet-name>
<description> Added to compile JSPs with debug info </description>
<servlet-class> org.apache.jasper.servlet.JspServlet </servlet-class>
<init-param>
<param-name> classdebuginfo </param-name>
<param-value> true </param-value>
</init-param>
<load-on-startup> 3 &