Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=21fgd","sa",""); Statement stmt=con.createStatement(); ResultSet rst=stmt.executeQuery("select count(*) from admin where username='"+uname+"' and password='"+pword+"'"); int count=0; if(rst.next()) { count=rst.getInt(1); }
贴出部分代码大家帮你看看
也就是你的key,
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.sql.*" errorPage="" %><%
String uname=new String(request.getParameter("username").getBytes("ISO8859_1"),"GBK");String pword=new String(request.getParameter("password").getBytes("ISO8859_1"),"GBK");try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=21fgd","sa","");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select count(*) from admin where username='"+uname+"' and password='"+pword+"'");
int count=0;
if(rst.next())
{
count=rst.getInt(1);
}
if(count!=1)
{
rst.close();
stmt.close();
con.close();
response.sendRedirect("err_login.jsp");
}
session.setAttribute("key","true");
rst.close();
stmt.close();
con.close(); response.sendRedirect("index.jsp");
}
catch(Exception e)
{
out.println(e);
}
%>
--------------------------------
index.jsp里我就弄了一句<%
out.println(session.getAttribute("key"));
%>
显示是NULL
<head><title></title></head>
<frameset cols='*' rows='*, 0'>
<frame src='http://服务器IP地址' frameborder='0' scrolling='Auto' noresize marginwidth='0' marginheight='0'>
</frameset>
<!--
<noframes><body>Frame required.</body></noframes>
-->
</html>
每次页面变换后那个服务器IP地址都是一样的相当于重开了另一个页面导致SESSION失效
这个是不是服务商没弄好的缘故?现在我的标题也无法正常显示了