servlet跳出frameset框架

时间:2022-11-09 16:38:57

servlet跳出frameset框架

代码如下:

package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import tools.DebugPrintf;

public class WanJiaExitSystem extends HttpServlet {

/**
* Constructor of the object.
*/
public WanJiaExitSystem() {
super();
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String msg=String.format("来源地址:"+request.getHeader("referer"));
DebugPrintf.Printf(msg);

request.getSession().removeAttribute("wanjia");

//servlet跳出frameset框架
//out.println("<script>window.parent.location.href('/index.html')</script>");
PrintWriter out = response.getWriter();
String url="<script>window.parent.location.href('";
url+=request.getContextPath();
url+="/index.html')</script>)";
DebugPrintf.Printf(url);
out.println(url);
}

}