JSP的login程序代码

2016-01-29 12:09 5 1 收藏

JSP的login程序代码,JSP的login程序代码

【 tulaoshi.com - Java 】

  JSP的login程序代码

<!-- Login Manager -->
<JAVA TYPE="class">

public static boolean checkUserPermission(HttpSession mySession, HttpServletRequest request, HttpServletResponse response)
{
if (mySession.getValue("hasPermission") == null || !((Boolean) mySession.getValue ("hasPermission" )).booleanValue())
{
String requestedUrl = HttpUtils.getRequestURL(request).toString();
String queryString = request.getQueryString();
if (queryString != null)
{
requestedUrl = requestedUrl + "?" + queryString;
}
requestedUrl = response.encodeUrl(requestedUrl);
mySession.putValue("requestedUrl", requestedUrl);
return false;
}
else
{
return true;
}
}

</JAVA>

<%
// JSP文件
String goodUser = "bill";
String goodPass = "bobo";
HttpSession mySession = request.getSession(true);
String errorMessage = "Please Login To Access The Page You Requested";
boolean loginAttempt = false;
String myMethod = request.getMethod();
if (request.getParameterValues("click") != null && request.getParameterValues ("click")[0].trim().equals("Log In"))
{
loginAttempt = true;
}

if (loginAttempt)
{
String username = request.getParameterValues("user")[0].trim();
String password = request.getParameterValues("pass")[0].trim();
//out.println("username = |" + username + "| & password = |" + password + "|<BR>");
if (goodUser.equals(username) && goodPass.equals(password))
{
response.sendRedirect((String)mySession.getValue("requestedUrl"));
mySession.putValue("hasPermission", new Boolean(true));
errorMessage = "Unable to redirect: " + (String) mySession.getValue("requestedUrl");
}
else
{
errorMessage = "You did not get the Username or Password right";
}
}
else
{
errorMessage = "Haven't tried logging in yet.";
if (mySession.getValue("requestedUrl") == null)
{
mySession.putValue("requestedUrl", "/index.jsp");
}
//out.println("set userReferrer to " + mySession.getValue("redirectTo") + "<BR>");
}
%>

<CENTER>
<font color=red><%=errorMessage%></font>
<TABLE align=center>
<FORM action="adminLogin2.jsp" method=post name="login">
<TR>
<TD>Username:</TD>
<TD><input type=text name=user value=""></TD>
</TR>
<TR>
<TD>Password:</TD>
<TD><input type=password name=pass value=""></TD>
</TR>
<TR>
<TD colspan=2 align=center><input type=submit name=click value="Log In"> </TD>
</TR>
</FORM>
</TABLE>
</CENTER>
Original URL: <%= (String)mySession.getValue("requestedUrl") %>
<script language="Javascript">
// <!--
if (document.forms.login != null)
document.forms.login.user.focus();
// -->
</script>
  5.11 checkbox在jsp中的使用方法



<%@ page language="Java" contentType="text/html" %>
<%@ page import="com.ora.jsp.util.*" %>
<html>
<body bgcolor="white">
<form action="checkbox.jsp">
<input type="checkbox" name="fruits" value="Apple">Apple<br>
<input type="checkbox" name="fruits" value="Banana">Banana<br>
<input type="checkbox" name="fruits" value="Orange">Orange<br>
<input type="submit" value="Enter">
</form>

<%
String[] picked = request.getParameterValues("fruits");
if (picked != null && picked.length != 0) {
%>
You picked the following fruits:
<form>
<input type="checkbox" name="fruits" value="Apple"
<%= ArraySupport.contains(picked, "Apple")?"checked" : "" %> >Apple<br>
<input type="checkbox" name="fruits" value="Banana"
<%= ArraySupport.contains(picked,"Banana")?"checked":"" %> >Banana<br>
<input type="checkbox" name="fruits" value="Orange"
<%= ArraySupport.contain

来源:http://www.tulaoshi.com/n/20160129/1484860.html

延伸阅读
  一直以来我们都希望我们的代码在不影响可读、可维护、可移植等条件下尽可能的短小精悍。       对于编程发烧友来说将代码的精简做极致,往往会比较变态,今天我也变了一把,时刻准备着各位拍砖。       事情是这样的,有个朋友说他写了个彩票机先程序,然后群里开始...
数据库表的结构必须有以下字段:   screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://ent.omeweb.com/book/admin/arti_ad/eWebE...
标签: ASP
  '*****************************************************  ' 创建一个WebServer  ' 必须参数:WRoot,为创建站点的物理目录;WComment为站点说明;WPort为站点端口;ServerRun为是否自动运行  ' 当创建成功时返回1,失败时提示退出并返回0,当创建站点成功但启动失败时返回2  '******************************...
标签: Web开发
可见使用Hibernate,在进行查询分页的操作上,是具有非常大的灵活性,Hibernate会首先尝试用特定数据库的分页sql,如果没用,再尝试Scrollable,如果不行,最后采用rset.next()移动的办法。 (一)pager类 * @(#)Pager.java 2005-5-3 * * Copyright (c) 2005, Jeffrey Hsu */ package com.jeffrey.messagelove; /** * Pager holds the p...
标签: Java JAVA基础
  下面是我用JSP和数据库做的购物车的源程序: 注意: 1、重新计费部分还没有做好,大家自己动手吧! 2、下一版本将用session做。 //shop_cart.jsp <%@ page contentType="text/html;charset=gb2312"% <%@ page session="true" % <%@ page language="java" import="java.sql.*" % &l...

经验教程

938

收藏

23
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部