login.jsp<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="images/web.css" rel="stylesheet" type="text/css">
</head><body>
<p> </p>
<p> </p>
<p> </p>
<table width="300" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000066">
<tr>
<td height="25">
<div align="center"><font color="#FFFFFF"><strong>请先登陆</strong></font></div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<form name="form1" method="post" action="login_in.jsp">
<table width="100%" border="0">
<tr>
<td>
<div align="right">用户名:</div></td>
<td>
<input name="yhm" type="text" id="yhm"></td>
</tr>
<tr>
<td>
<div align="right">密 码:</div></td>
<td>
<input name="yhmm" type="password" id="yhmm" value=""></td>
</tr>
<tr>
<td>
<div align="right"></div></td>
<td>
<input type="submit" name="Submit" value="登陆">
<input type="reset" name="Submit2" value="取消"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
logincheck.jsp<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><jsp:useBean id="wu" scope="page" class="wu.jdbc" />
</head><body>
<%
String yhm = request.getParameter("yhm") ;
String yhmm = request.getParameter("yhmm") ;
Connection con = wu.getConn() ;
Statement stmt = con.createStatement() ;
String sql = "select * from user where name = '" + yhm + "' pwd = '" + pwd + "'" ;
ResultSet rs = stmt.executeQuery(sql) ;if(rs.next()){
session.setAttribute("login","1");
response.sendRedirect("1.jsp");
}else{
response.sendRedirect("login.jsp");}
%>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="images/web.css" rel="stylesheet" type="text/css">
</head><body>
<p> </p>
<p> </p>
<p> </p>
<table width="300" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000066">
<tr>
<td height="25">
<div align="center"><font color="#FFFFFF"><strong>请先登陆</strong></font></div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<form name="form1" method="post" action="login_in.jsp">
<table width="100%" border="0">
<tr>
<td>
<div align="right">用户名:</div></td>
<td>
<input name="yhm" type="text" id="yhm"></td>
</tr>
<tr>
<td>
<div align="right">密 码:</div></td>
<td>
<input name="yhmm" type="password" id="yhmm" value=""></td>
</tr>
<tr>
<td>
<div align="right"></div></td>
<td>
<input type="submit" name="Submit" value="登陆">
<input type="reset" name="Submit2" value="取消"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
logincheck.jsp<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><jsp:useBean id="wu" scope="page" class="wu.jdbc" />
</head><body>
<%
String yhm = request.getParameter("yhm") ;
String yhmm = request.getParameter("yhmm") ;
Connection con = wu.getConn() ;
Statement stmt = con.createStatement() ;
String sql = "select * from user where name = '" + yhm + "' pwd = '" + pwd + "'" ;
ResultSet rs = stmt.executeQuery(sql) ;if(rs.next()){
session.setAttribute("login","1");
response.sendRedirect("1.jsp");
}else{
response.sendRedirect("login.jsp");}
%>
</body>
</html>
解决方案 »
- 网页抓取出错,跟编码有关!求助!
- request.getContentPath()为什么找不到此方法呢?
- 字符串取值问题
- jsp上传文件和下载文件的问题
- Properties prop = new Properties(); Properties是做什么用的
- 菜鸟问题!高分求教将html文件转化成jsp文件
- 急!!!保存记录的问题?
- struts传参问题
- 请问大家写JSP的时候charset用gb2312还是gbk??
- 请问:如何使用java实现数据库表的导出,比如把access中导成.txt文件
- 紧急求救!!(Linux 8.0环境下)jsp+tomcat+oracle9i配置的问题,tomcat配置成功,数据库正常工作,但是在jsp访问数据库时:?出错信息为
- 一个JavaBean 问题?
testsqlserver.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
根据例子程序自己来根据需要和本身的资源来做数据库的问题!
String sql = "select * from user where name = '" + yhm + "' pwd = '" + pwd + "'" ;这样认证可行吗?考虑一下 ' or 等非法字符吧!!
还有就是怎样连接SQLSERVER?大家已经说的很明白了
ACTION地址是用JSP处理好还是用SERVLET?根据个人喜好了。Servlet的封装性更好些,调试起来也方便些,好维护些