当前位置: 代码迷 >> Java Web开发 >> 期終考試題目,國外朋友的,俺不會jsp只好請教大大門 PART 2解决思路
  详细解决方案

期終考試題目,國外朋友的,俺不會jsp只好請教大大門 PART 2解决思路

热度:466   发布时间:2016-04-17 16:04:38.0
期終考試題目,國外朋友的,俺不會jsp只好請教大大門 PART 2
B. A   website   login   mechanism.
Create   a   web   application   where   the   user   can   login   and   browse   the   context   of   a   website.   Access   to   the   website   should   not   be   allowed   to   non   logged   in   users.
创建一个网络应用,用户能够登陆并且浏览这个网站。没有登陆的用户不能进入该网站。
a. First   create   a   JSP   file   with   all   the   necessary   HTML   and   JSP   elements,   and   call   it   index.jsp.
b. Add   one   text   element   on   the   page   where   the   user   enters   the   username   and   one   password   element   where   the   user   enters   the   password.
c. Add   a   submit   type   button   on   the   page   so   that   when   the   user   clicks   on   it,   the   page   is   submitted   to   the   server.   The   action   of   the   form   element   in   the   page   should   refer   back   to   the   index.jsp   page.
d. Before   submitting   the   page,   validate   (using   JavaScript)   the   following:
i. username   and   password   fields   are   not   empty   or   contain   any   white   spaces
ii. username   and   password   are   longer   than   7   characters,   but   16   maximum

e. Username   and   password   verification   should   be   done   by   a   session   type   JavaBean   (say   login.java)   that   is   called   from   within   index.jsp.
f. Create   the   login   JavaBean   and   have   a   function   called   checkUser(username,   password)   that   will   return   true   if   the   username   and   password   are   correct   or   false   otherwise.   The   function   should   also   store   the   username   and   login   result   within   local   variables.
g. Usernames   and   passwords   should   already   exist   in   the   users   table   in   a   database   (see   Further   Information   section),   and   the   JavaBean   should   access   the   dbConnector.java   JavaBean   created   in   part   A   to   access   and   retrieve   the   password   details.

NOTE:   To   get   started,   if   you   have   not   /   cannot   do   part   A,   you   can   just   hardcode(在编程过程中可以把变量赋值为自己造的数据,用于测试)   the   username   and   password   list   within   the   login.java   JavaBean.

h. The   login   JavaBean   should   also   have   other   useful   functions   like   a   function   that   returns   the   login   status   or   a   function   that   returns   the   username   (or   full   name   of   user).
i. If   the   login   is   successful,   then   index.jsp   should   redirect   the   user   to   a   new   page   (say   main.jsp).   Otherwise,   if   unsuccessful   login,   the   page   should   keep   the   user   in   the   login   page   and   display   a   login   failure   message.
  相关解决方案