我在messagelist.jsp页面是这样获取的,运行时报错,请问应该怎么该啊?
<%
String num=new String(request.getSession().getAttribute("num").toString());

System.out.println(num);
if(num==null)
{
window.location="viewMessage.do";

}
else if(num.equals("0"))
{
out.print("<script>alert('复选框没有被选中!');</script>");
}
else
{
out.print("<script>alert('删除成功!');</script>");
}
%>Exception:严重: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: ServletException in '/pages/messagelist.jsp': Unable to compile class for JSPAn error occurred at line: 18 in the jsp file: /pages/messagelist.jsp
Generated servlet error:
window.location cannot be resolved to a type

解决方案 »

  1.   

    window.location="viewMessage.do"; 这一句有错,它不是java语句,应该给javascript解释。所以,这一句改为: out.print(" <script>  window.location = \"viewMessage.do\"; </script> ");
      

  2.   

     Unable   to   compile   class   for   JSP 
    这个错是说你  调用了未知的 类   
    window.location="viewMessage.do"; 应该改为
    window.location.href ="viewMessage.do"; 
      

  3.   

    OK,同意3楼部分说法,window.location.href 才是正确的javascript语句。但不能直接在java代码区域使用,应该写为:
     out.print("   <script>     window.location.href   =   \"viewMessage.do\";   </script>   ");
      

  4.   

    我总怀疑你这句 是不是有问题啊?
    String   num=new   String(request.getSession().getAttribute("num").toString()); 首先你要确定request.getSession().getAttribute("num")  不为 NULL,
    其次 假如它不为NULL,那么它的toString(),已经是得到它的String形式的值了,搞不明白为什么还有去
    new String (....)顺便对 4楼的 朋友说一声,lz的那个out.print(.....)也是对的,别人里面用的是 单引号,你没有看清楚吧?
      

  5.   

    但是该了后提示这个错误了是为什么呢?我已经对它的值为null时做出响应了为什么还提示这个错误啊?严重: ServletException in '/pages/messagelist.jsp': null
    org.apache.jasper.JasperException
      

  6.   

    这样写应该不会出错:
    <%
      String num = null;
      if (request.getSession().getAttribute("num") != null) {
        num =  request.getSession().getAttribute("num").toString();
        System.out.println(num);
      }
      if (num == null) {
        out.print("       <script>           window.location.href       =       \"viewMessage.do\";       </script>       ");
      }
      else if (num.equals("0")) {
        out.print(" <script> alert('复选框没有被选中!'); </script> ");
      }
      else {
        out.print(" <script> alert('删除成功!'); </script> ");
      }
    %>