用JSP实现一个简单的登陆程序

时间:2014.11.03 发布人:xieshic

用JSP实现一个简单的登陆程序

已解决问题

谷歌xieshic用户在2014.11.03提交了关于“夺冠用JSP实现一个简单的登陆程序”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2025-02-27T03:37:55。

要求应用J**aBean来年接收用户输入的用户名和密码,然后判断输入的用户名是否为“admin”、密码是否为‘’000‘’,若是,则转发到success.jsp页面显示“欢迎登陆”提示信息,否则转发到fault.jsp页面显示“登陆失败”提示信息。求大神们帮帮忙!很急!!!

希望大家能够帮助她。

详细问题描述及疑问:

要求应用J**aBean来年接收用户输入的用户名和密码,然后判断输入的用户名是否为“admin”、密码是否为‘’000‘’,若是,则转发到success.jsp页面显示“欢迎登陆”提示信息,否则转发到fault.jsp页面显示“登陆失败”提示信息。求大神们帮帮忙!很急!!!

期待您的答案,滴水之恩,来日我当涌泉相报 !
希望以下的回答,能够帮助你。

第1个回答

用户名:无限问答剑制所成  

<html>
<head>


<title>MyJS行医活形限医待染志应P'test.jsp'startin苏所越你永镇后讨妈益gpage</titl计明者诉基环束食e>

<metahttp-equiv="pragma"content="n议社华属所青仅o-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<m反孔阶入议力房历真微etahttp-equiv="description"conte期身及nt="Thisismypage">
<!--
<linkrel="styl木斤础弦企觉esheet"type="text/css"href="styles.括鲁绍左径福css">
-->

</head>

<body>
<formaction="servlet"method="post">
用户名:
<inputtype="text"name="name"/>
<b假概r/>
密码:
<inputtype="passwo粒点息来讲序材服新rd"name="pwd"/>
<b种缩批防乙r>
<inputtype="submit"value="提交"/>
</form>


</body>
</html>

上面的这些是登陆页

publi执发她又cvoiddoGe操晚控缩双征乡包照t(h**ttpServletRequestrequest错即坏,h**ttpServletResponseresponse)
throwsServletException,IOException{

this.doPost(request,response);
}

/**
*ThedoPostmethodoftheservlet.<b响过妈片单胞适r>
*
*Thismethodiscalledwhenaf衡客劳即目ormhasitstagvaluemethodequalstopost.
*
*@paramrequesttherequestsendbytheclienttotheserver
*@paramresponsetheresponsesendb祖矛入政般ytheservertotheclient
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoPost(h**ttpServletRequestrequest,h**ttpServletResponseresponse)
throwsServletException,IOException{

response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
Stringname=request.getParameter("name");
Stringpwd=request.getParameter("pwd");
if("admin".equals(name)&&"000".equals(pwd)){
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("fault.jsp");
}
}

这是servlet代码

至于success.jsp和fault.jsp

只需要在body分别打上欢迎登陆或者登陆失败就行了