高手快过来呀,本人刚学,可是老师留的作业我实在不会了,我会努力,但是希望高手能帮我编一下,我感激不尽!!!好人一生平安!!!
所需建立的 jsp 网页有三个:
 登入页面(login.jsp)
 完成登入的页面(showmsg.jsp)
 注销页面(logout.jsp)
1.  登入页面(login.jsp)
判断 session 变量是否已经存在,如果不存在(第一次联机或 session 物 件已消失),则印出两个文本框给使用者输入姓名及 E-Mail(无预设 值),但不需要检查有没有输入,按下送出按钮执行 showmsg.jsp。
如果 session 变量已经存在(已经登入),则不印出登入用的 Form,而 是从 session 变量中取得姓名及 E-Mail,显示在浏览器上,另外还有一 个按钮作为注销之用,按下后执行 logout.jsp 
2.  完成登入的页面(showmsg.jsp)
先詴着取得从 form 传来的变量(姓名及 E-Mail),如果这些变量不存
在,将网页导向登入页面(用 sendRedirect)重新登入。
判断 session 变量是否存在,如果 session 变量不存在,则建立新的 session
变量,并印出“设定 session 变量”文字。
在浏览器上显示姓名及 E-Mail。
建立两个连结,一个连到登入页面(至 login.jsp),一个连到注销页面
(至 logout.jsp)。
连到注销页面(logout.jsp),应该由 logout.jsp 判断这不是从 login.jsp  的 登 出 按 钮 传 过 来 的 , 需 将 网 页 导 向 登 入 页 面 ( 用 sendRedirect),必须由用户按了注销按钮才能注销,所以会出现《图 二》的画面,也就是没有登入用的 Form,而有姓名、E-Mail、及注销 按钮的画面。
3.  注销页面(logout.jsp)
先詴着取得从「注销按钮」传来的变量,如果此变量不存在(不是按了
「注销按钮」才连到 logout 页面,而是由其他方式连过来,或是直接在浏览器的网址输入 logout.jsp),则将网页导向 登入页面(用 sendRedirect),重新注销。
如果可以取得从「注销按钮」传来的变量,则删除 session  对象
(invalidate),并印出“已成功注销!”。
建立一个返回登入页面(至 login.jsp)的连结。如下图所示:
此时 session 对象已经删除,如果连到 login.jsp 应该出现的登 入画面(无默认值)。

解决方案 »

  1.   

    汗。。像这样 登陆的 网上一大把啊
     在说你学Java的时候 像登陆的例子的 应该很常见了啊··  自己摸索着写。。还好些 。。那样你能学到东西别人想的始终是别人的 
    自己想的 才到以后 有用处。。会记得。。
      

  2.   

    没人比我快!
    login.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      </head>  
      <body>
      <%
       if(session.getAttribute("username")!=null&& session.getAttribute("email")!=null){
     %> 
       username:<%=session.getAttribute("username")%>
       email:<%=session.getAttribute("email")%>
      
       <%}else{%>
       <form action="showmsg.jsp" method="method">
       username<input type="text" name="username" value=""><br>
       email<input type="text" name="email" value=""><br>
       <input type="submit" value="submit"/>  
       </form>
      
           <%}%>
        
      </body>
    </html>
    showmsg.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'showmsg.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
        <%
        
               out.print(request.getParameter("username")+" "+request.getParameter("email"));
          session.setAttribute("username",request.getParameter("username"));
          session.setAttribute("email",request.getParameter("email"));
          %>
        <br>
        <a href="logout.jsp">exit</a>
      </body>
    </html>logout.jsp
    <%
    session.invalidate();
    response.sendRedirect("login.jsp");
     %>
      

  3.   


    3页共15行 其它都是HTML代码 我懒的删了 所以看上去多,其实一点点 而且还有没有数据库验证客户端验证 多简单 楼主给分丫
      

  4.   

    别火了,给你贴一个,以后好好学,这个不难的。
    login.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
      </head>
      
      <body>
    <form action="showmsg.jsp" method="post"/>
       Emial:<input type=text name=email value=""/><br/>
    PassWord:<input type=password name=password value=""/>
    <br/><input type=submit value="登录"/>
    </form>
      </body>
    </html>
    doLogin.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%
    request.setCharacterEncoding("GBK");
    String email=request.getParameter("email");
    session.setAttribute("email",email);
    response.sendRedirect("showmsg.jsp");
    %>showmsg.jsp<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'doLogin.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
       <%String email=(String)session.getAttribute("email");
       if(email==null)
       {
        response.sendRedirect("login.jsp");
       }
       else
       {
        out.print(email);
       }
       
        %>
    <a href="loginout.jsp">注销登录</a>
      </body>
    </html>loginout.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%
    session.invalidate();
    response.sendRedirect("login.jsp");
     %>
      

  5.   

    这个题可以作为学习JSP练手用。
    建议LZ消化后自己重新设计,得加些要求,呵呵
      

  6.   

    登录系统是最基本的jsp练习~lz动手做一下就明白了~