❶ 用web+SQLserver+jsp编写登录界面。要求有验证
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<html>
<head>
<title>人事管理系统登录界面</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
.STYLE3 {font-size: 24px}
-->
</style>
</head>
<%
String career=request.getParameter("career");
String usernum=request.getParameter("usernum");
String password=request.getParameter("password");
String sql="";
if(career=="管理员")
sql="select * from secret where eno='"+usernum+"' and sec='"+password+"'";
else
sql="select * from password where eno='"+usernum+"' and pwd='"+password+"'";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=J2EE", "sa", "123456");
PreparedStatement pstmt = conn.prepareStatement();
ResultSet rs = pstmt.executeQuery(sql);
if(career=="管理员"&&rs!=null)
request.sendRedirect("management.jsp");
else if(career=="普通用户"&&rs!=null)
request.sendRedirect("common.jsp");
else
{
PrintWriter out = response.getWriter();
out.write("<script>alert('登陆失败!')</script>");
request.sendRedirect("manager.jsp");
}
%>
❷ 怎么用JSP写个论坛登录界面代码
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage="../error.jsp" %>http://www.w3.org/TR/html4/loose.dtd"></A><%String ID = request.getParameter("ID");String password = request.getParameter("password");String info = "0";Connection con = null;Statement sm = null;ResultSet rs = null;try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost/mydb1"; con = DriverManager.getConnection(url,"root","admin"); sm = con.createStatement(); rs = sm.executeQuery("select * from userinfo where userid='"+ID+"'"); if(rs.next()) { if(rs.getString("password").equals(password)) { response.sendRedirect("../index.jsp"); session.setAttribute("user",ID); } else response.sendRedirect("login.jsp?info=2"); } else { response.sendRedirect("login.jsp?info=1");; }}catch(Exception e){ e.printStackTrace();} finally { if(rs!=null) { try{ rs.close();}catch(Exception e){e.printStackTrace();} } if(sm!=null) { try{ sm.close();}catch(Exception e){e.printStackTrace();} } if(con!=null) { try{ con.close();}catch(Exception e){e.printStackTrace();} } }%>
❸ 用jsp实现一个简单的登录界面,主要是验证码
<html>
<head>
<title>简单页面</title>
<script>
function yzm(){
var Num="";
for(var i=0;i<4;i++)
{
Num+=Math.floor(Math.random()*10);
}
document.getElementById("yzphoto").value=Num;
document.getElementById("yzm").value=Num;
}
function userLogin(){
var userName = document.getElementById("userName").value;
var password = document.getElementById("password").value;
var yztext = document.getElementById("yztext").value;
var yzm = document.getElementById("yzm").value;
if(userName != "jq"){
alert("用户名错误");
}else if(password != "123"){
alert("密码错误");
}else if(yztext != yzm){
alert("验证码错误");
}else{
alert("登陆成功");
}
location.reload();
}
</script>
</head>
<body onLoad="yzm()">
<div style="width:100%;text-align:center">
<h1>用户登录</h1>
<table>
<tr>
<td>用户名:</td>
<td><input id="userName" type="text" value=""/></td>
</tr>
<tr>
<td>密码:</td>
<td><input id="password" type="password" value=""/></td>
<tr>
<tr><td>
验证码:
</td>
<td><input id="yztext" type="text" value=""/><input style="width:50px;background-
color:red;color:blue" type="text" id="yzphoto" value=""/><input type="hidden" id="yzm"
value=""></td></tr>
<tr>
<td colspan="2" align="center"><input onclick="userLogin()" type="button" value="登陆"/></td>
</tr>
</table>
</div>
</body>
</html>
❹ 用JSP和servlet做一个用户登录。
你好:
这个第一点,可以在web.xml当中配置过滤器,实现此功能,
例如:购物之后,放进购物车,准备付款的时候,需要验证是否登录,若未登录,需要重定向到登陆界面。
第2点当然要用的session、或者是application
这些都是JSP的内置对象,可以绑定一些用户的信息。
❺ jsp登陆界面源代码
1、login.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录页面</title>
</head>
<body>
<form name="loginForm" method="post" action="judgeUser.jsp">
<table>
<tr>
<td>用户名:<input type="text" name="userName" id="userName"></td>
</tr>
<tr>
<td>密码:<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" value="登录" style="background-color:pink"> <input
type="reset" value="重置" style="background-color:red"></td>
</tr>
</table>
</form>
</body>
</html>
2、judge.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>身份验证</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(name.equals("abc")&& password.equals("123")) {
3、afterLogin.jsp文件
%>
<jsp:forward page="afterLogin.jsp">
<jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录成功</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
out.println("欢迎你:" + name);
%>
</body>
</html>
java web登录界面源代码:
1、Data_uil.java文件
import java.sql.*;
public class Data_uil
{
public Connection getConnection()
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="***";
String password="***";
String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***";
Connection con=null;
try{
con=DriverManager.getConnection(url,user,password);
}catch(SQLException e)
{
e.printStackTrace();
}
return con;
}
public String selectPassword(String username)
{
Connection connection=getConnection();
String sql="select *from login where username=?";
PreparedStatement preparedStatement=null;
ResultSet result=null;
String password=null;
try{
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,username);
result=preparedStatement.executeQuery();//可执行的 查询
if(result.next())
password=result.getString("password");
}catch(SQLException e){
e.printStackTrace();
}finally
{
close(preparedStatement);
close(result);
close(connection);
}
System.out.println("找到的数据库密码为:"+password);
return password;
}
public void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
2、login_check.jsp:文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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=utf-8">
<title>验证用户密码</title>
</head>
<body>
<jsp:useBean id="util" class="util.Data_uil" scope="page" />
<%
String username=(String)request.getParameter("username");
String password=(String)request.getParameter("password");
if(username==null||"".equals(username))
{
out.print("<script language='javaScript'> alert('用户名不能为空');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
else
{
System.out.println("输入的用户名:"+username);
String passwordInDataBase=util.selectPassword(username);
System.out.println("密码:"+passwordInDataBase);
if(passwordInDataBase==null||"".equals(passwordInDataBase))
{
out.print("<script language='javaScript'> alert('用户名不存在');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
else if(passwordInDataBase.equals(password))
{
out.print("<script language='javaScript'> alert('登录成功');</script>");
response.setHeader("refresh", "0;url=loginSucces.jsp");
}
else
{
out.print("<script language='javaScript'> alert('密码错误');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
}
%>
</body>
</html>
3、loginSucces.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<hr size="10" width="26%" align="left" color="green">
<font size="6" color="red" >登录成功 </font>
<hr size="10" width="26%" align="left" color="green">
</body>
</html>
4、user_login.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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=ISO-8859-1">
<title>登录界面</title>
</head>
<body background="C:Userswin8workspaceLoginimage\_10.jpg" >
<center>
<br><br><br><br><br><br>
<h1 style="color:yellow">Login</h1>
<br>
<form name="loginForm" action="login_check.jsp" method="post">
<table Border="0" >
<tr >
<td>账号</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password">
</td>
</tr>
</table>
<br>
<input type="submit" value="登录" style="color:#BC8F8F">
</form>
</center>
</body>
</html>
❻ JSp登陆界面
给你个思路。
新建个连接数据库的类。
里面有各种操作数据库的方法
打个比方 类中有个到数据库查询用户名和密码的方法
public boolean checkInfo(String name,String pwd)
{
连接数据库验证name和pwd
如果存在返回true 否则返回false
}
为什么返回类型要用布尔型呢?
因为你可以在JSP页面把name和pwd直接传给这个类来处理。
尽量少在<% %>写代码。
取回checkInfo的返回信息
boolean bool = checkInfo(name,pwd);
这样你的if(?????).可以写成
if(bool)
{
真:转向22.jsp
}else{
转向11.jsp
}
❼ 用jsp怎样做一个用户登录界面
//jsp文件,登录界面
<%@pagepageEncoding="utf-8"contentType="text/html;charset=utf-8"%>
<body>
<h1>Register</h1>
<hr/>
<formaction="login"method="post">
用户名:
<inputtype="text"name="username"id="text"/>
密码:
<inputtype="password"name="pwd"id="text"//>
<inputtype="submit"value="登录"id="button"/>
</form>
</body>
//这是server文件,web.xml部署名字login
importjava.io.IOException;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpSession;
{
publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
Stringusername=request.getParameter("username");
Stringpwd=request.getParameter("pwd");
try{
if(username.equals("name")&&pwd.equals("pwd")){
system.out.print("登录成功");
}else{
system.out.print("error");
}
}catch(Exceptione){
e.printStackTrace();
}
}
}
简单的登录界面,不需要数据库,如果要链接数据库就要判断很多了
❽ 如何用jsp设计登录界面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
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 'login.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>
<center>
<h3>用户登录</h3>
<s:form action="" method="post" theme="simple">
<table>
<tr>
<td>用户名:</td>
<td><s:textfield name=""></s:textfield> </td>
</tr>
<tr>
<td>密码:</td>
<td><s:password name=""></s:password> </td>
</tr>
<tr>
<td><s:submit value="登录"></s:submit> </td>
<td><s:reset value="取消"></s:reset> </td>
</tr>
</table>
</s:form>
</center>
</body>
</html>