我就想弄个,点击留言板,如果没登陆的话,会弹出你未登陆,然后跳转到登陆页面;如果登录的话直接进入留言板页面
我的登录是在首页的一个地方我的留言板验证代码如下:
<title>无标题文档</title>
</head><body>
<%String username2=(String)session.getAttribute("login_name");
if( username2==null){%>
 <script>alert('您未登陆,请登陆后在留言!');document.location='index.jsp?choice=7';</script>
<%}else{}%>
</body>
</html>
现在有两个问题,第一是没登陆的情况下那个弹框不会出现,第二是我登陆了之后他还是不会跳转到留言板,请帮我解决下,修改下我的代码。谢谢

解决方案 »

  1.   


    <title>无标题文档</title>
    </head><body>
    <%
    String opStr="alert('操作失败!');history.back();";
    String username2=(String)session.getAttribute("login_name");
    if( username2==null){%>
    opStr =“alert('您未登陆,请登陆后在留言!');self.location='index.jsp?choice=7';”;
    <%}else{}%>
    </body>
    </html>
    <script language="javascript"><%=opStr%></script>
    这样写应该可以,防止未登录进入页面可以写过滤器,没必要在每个页面都判断一下session中是否有值...
      

  2.   


    <title>无标题文档</title>
    </head><body>
    <%
    String opStr="alert('操作失败!');history.back();";
    String username2=(String)session.getAttribute("login_name");
    if( username2==null){
    opStr =“alert('您未登陆,请登陆后在留言!');self.location='index.jsp?choice=7';”;
    }else{}%>
    </body>
    </html>
    <script language="javascript"><%=opStr%></script>之前发的错了,这个好用....
      

  3.   

    1是你script标签每写全
    <script language="javascript">
    </script>
      

  4.   

    <script>alert('您未登陆,请登陆后在留言!');document.location='index.jsp?choice=7';</script>楼主,你确定是document.location?