用lomboz_eclipse,在学习jsp网站设计时,弄了个登陆和管理页面,直接在网址栏打管理页面的域名是不能进去的,一定要登陆才能进去。
但登录过一次以后,在地址栏直接打管理页面的域名也能登录进去,教程说是在同一个页面,关了从新打开就没事。
但我关了,还是能直接进去;在lomboz_eclipse理把Tomcat服务器关了重启还是能直接进去。
把lomboz_eclipse关了,再启动,就要经过登陆页面才能进去是不是我电脑的问题?还是配置的问题?还是其他的问题?有没有具体解决的办法???

解决方案 »

  1.   

    你的登录时用什么来记录的Session还是Cookie ?贴代码..这种问题没代码..不好看呐。
      

  2.   

    教程的意思应该是把登录信息放在session中了,你看看代码
      

  3.   


    是用Session的<%@ page language="java" contentType="text/html; charset=gbk"
        pageEncoding="gbk"%>
    <%@ page import="java.sql.*" %><%
    String admin = (String)session.getAttribute("admin");
    if(admin != null && admin.equals("true")){
    login = true;
    }
    %>
    <%!
    String str = "";
    boolean login = false;
    private void tree(Connection conn,int id,int level){
    Statement stmt = null;
    ResultSet rs = null;
    String preStr = "";
    for(int i=0;i<level;i++){
    preStr += "----";
    }
    try{
    stmt = conn.createStatement();
    String sql = "select * from article where pid= " + id;
    rs = stmt.executeQuery(sql);
    String strLogin = "";

    while(rs.next()){
    if(login){
    strLogin = "<td><a href='Delete.jsp?id=" +rs.getInt("id") + "&pid=" + rs.getInt("pid") +"'>删除</a>"; 
    }
    str +="<tr><td>" + rs.getInt("id") + "</td><td>"  +
    preStr + "<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>"  + 
    rs.getString("title") + "</a></td>" + 
    strLogin +
    "</td></tr>";
    if(rs.getInt("isleaf") != 0){
    tree(conn,rs.getInt("id"),level+1);
    }
    }
    }catch(SQLException e){
    e.printStackTrace();
    }finally{
    try{
    if(rs != null){
    rs.close();
    rs = null;
    }
    if(stmt != null){
    stmt.close();
    stmt = null;
    }
    }catch(SQLException e){
    e.printStackTrace();
    }
    }
    }
    %><%
    Class.forName("com.mysql.jdbc.Driver");
    String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
    Connection conn = DriverManager.getConnection(url);Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from article where pid = 0");
    String strLogin = "";
    while(rs.next()){
    if(login){
    strLogin = "<td><a href='Delete.jsp?id=" +rs.getInt("id") + "&pid=" + rs.getInt("pid") +"'>删除</a>"; 
    }
    str +="<tr><td>" + rs.getInt("id") + "</td><td>"  +
      "<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" + 
          rs.getString("title") + "</a></td>" +
          strLogin +
          "</td></tr>";
    if(rs.getInt("isleaf") != 0){
    tree(conn,rs.getInt("id"),1);
    }
    }
    rs.close();
    stmt.close();
    conn.close();
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title>Insert title here</title>
    </head>
    <body>
    <a href="Post.jsp">发表新帖</a>
    <table border=1>
    <%= str %>
    <% 
    str = ""; 
    login = false;
    %>
    </table>
    </body></html>
      

  4.   

    你的浏览器是不是用的IE8啊。如果是IE8的话,重新开启一个浏览器,session是不会清掉的。。你可以换其他的浏览器试一下。。
      

  5.   

    session 引起的 但是没见在哪set 的
      

  6.   

    你在点击退出或者注销的时候,remove session没啊??
      

  7.   


    界面是在lomboz_eclipse里面打开的,我电脑是用IE8,但lomboz_eclipse里面是不是用IE8就不清楚,感觉就是一个展示界面的IE
      

  8.   

    一次login之后服务端会为你保存session,知道session到时或者invalidate()你的login状态才被清空。
    按道理服务器重启session应该被晴空了,估计楼主debug用的可能是eclipse自带的服务器吧。
    你把你的程序打个war包,部署到tomcat上脱离eclipse试一下。如果没问题,楼主就别担心了。
      

  9.   

       除了登录页面之外,在进入其它页面之前,         用 session 判断 用户名是否为空,                 为空,则跳转到登录页 面就可以解决了