jsp登录界面要怎么写
用户名和密码保存在user数据表中,下面是我的处理界面,要怎么写呢?实现的功能是:从index.jsp获得的数据传递到判断界面进行处理,如果和数据中保存的数据以致就登录。<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>身份验证</title>
</head>
<body>
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=user";
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
Connection conn = DriverManager.getConnection(url,name,password);
if (conn!=null){
out.print("数据库操作成功,恭喜你");
}
%>
</body>
</html>
--------------------编程问答-------------------- 简单点:点击提交到另一个jsp,然后判断上一个页面传过来的用户名和密码和是否在数据库user表中存在,如果存在转到成功的页面,失败转到失败的页面 --------------------编程问答-------------------- 那代码要怎么写?上面的代码会不会有哪里是错误的?我在登录界面输入之后提示说用户登录失败
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /judge.jsp at line 30
27:
28:
29:
30: Connection conn = DriverManager.getConnection(url,name,password);
31:
32:
33: if (conn!=null){
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'abc' 登录失败。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.judge_jsp._jspService(judge_jsp.java:111)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'abc' 登录失败。
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(Unknown Source)
com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(Unknown Source)
com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(DriverManager.java:582)
java.sql.DriverManager.getConnection(DriverManager.java:185)
org.apache.jsp.judge_jsp._jspService(judge_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.32 --------------------编程问答-------------------- javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'abc' 登录失败。 --------------------编程问答-------------------- Connection conn = DriverManager.getConnection(url,name,password);
这句好的意思是获取数据库连接,name和password是登陆mysql的用户名和密码(一般是root/root),而楼主你你登陆页面的用户名和密码当成数据库的用户名和密码了,导致用户名报错
ps:一般数据库用户名和密码是后台配置的
补充:Java , Java EE