当前位置: 代码迷 >> Java Web开发 >> jsp 代码运行一片空白
  详细解决方案

jsp 代码运行一片空白

热度:6810   发布时间:2013-02-25 21:21:43.0
jsp求助 代码运行一片空白
HTML code
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" errorPage="login.jsp"%><%    request.setCharacterEncoding("UTF-8");        String username = "";    int visitTimes = 0;    Cookie[] cookies = request.getCookies();    for(int i=0; cookies!=null&&i<cookies.length;i++) {        Cookie cookie = cookies[i];        if("username".equals(cookie.getName())) {            username = cookie.getValue();        }        else if("visitTimes".equals(cookie.getName())) {            visitTimes = Integer.parseInt(cookie.getValue());        }    }    if(username == null || username.trim().equals("")) {        throw new Exception("未登录,请先登录");    }        Cookie visitTimesCookie  =new Cookie("visitTimes", Integer.toString(++visitTimes));    response.addCookie(visitTimesCookie); %><html>  <head>    </head>  <body>  <div align="center">      <fieldset>          <legend>登录信息</legend>          <form action="login.jsp" method="post"></form>              <table>                  <tr>                      <td>你的帐号:</td>                      <td><%=username%></td>                  </tr>                  <tr>                      <td>登录次数</td>                      <td><%=visitTimes %></td>                  </tr>                  <tr>                      <td></td>                      <td>                          <input type="button" value="刷新" onclick="location='                          <%= request.getRequestURI()%>?ts='+new Date().getTime();" class="button">                      </td>                  </tr>              </table>      </fieldset>  </div>  </body></html>


------解决方案--------------------------------------------------------
我知道为啥了,你第一句话,把这个删除掉 “errorPage="login.jsp"”,出错又强制回登录界面了。

另外这段代码修改下:
if(username == null || username.trim().equals("")) {
System.err.println("未登录,请先登录");
}
就应该能看到了。