怎样在Servlet中打开一个新的浏览器窗口(100分)

  • 主题发起人 主题发起人 xao_hx
  • 开始时间 开始时间
X

xao_hx

Unregistered / Unconfirmed
GUEST, unregistred user!
通过Servlet可以调另外的页面,比如我做一个条件判断,符合条件时调页面A,不符合条件时调页面B.我使用disp.forward(request, response)的方法实现,可我想让调出的页面在新的窗口显示,该怎么办?
 
response.setContentType("text/html;
charset=GBK");
PrintWriter out= response.getWriter();
String str="";
if (true){
str += "<script language=/"JavaScript/">/n";
str += "<!--/n";
str += " window.open('111111.html');/n";
str += " //-->/n";
str += "</script>/n";
}
else
{
str += "<script language=/"JavaScript/">/n";
str += "<!--/n";
str += " window.open('11112222.html');/n";
str += " //-->/n";
str += "</script>/n";
}
out.print(str);
 
用7syw的方法,但这些javascript的代码不要在servlet那里写,写在你的forward的那个jsp里,servlet不要处理表示层的东西
 
情况是这样的:
我写一个Java文件,内容如下:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public voiddo
Get(HttpServletRequest request, HttpServletResponse
response)throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
然后编译,出现如下的错误,不知道如何解决,请各位大虾帮忙:
HelloWorld.java:2: package javax.servletdo
es not exist
import javax.servlet.*;
^
HelloWorld.java:3: package javax.servlet.httpdo
es not exist
import javax.servlet.http.*;
^
HelloWorld.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorld
public class HelloWorld extends HttpServlet
^
HelloWorld.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorld
public voiddo
Get(HttpServletRequest request, HttpServletResponse
^
HelloWorld.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorld
public voiddo
Get(HttpServletRequest request, HttpServletResponse
^
HelloWorld.java:8: cannot resolve symbol
symbol : class ServletException
location: class HelloWorld
response)throws IOException, ServletException
^
6 errors

 
你的环境变量设置了吗?
 
不知道你有没有这个包?
如果有的话就是环境变量设置的不正确
如果用JCreater之类的开发工具,直接在工程属性中加所需的包就行了
 
参考
http://www.java-cn.com
 
后退
顶部