SQL标签数据库里查用户名是中文的查不出来,英文可以。
蝙蝠骑士 2014-05-25 05:17:33 <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
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_ex.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>
<c:set var="password" value="${param.password}"/>
<c:set var="username" value="${param.username}"/>
<c:set var="name" value="${param.name}"/>
<c:set var="address" value="${param.address}"/>
<c:set var="loginsuccess" value="false"/>
<sql:setDataSource driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
user="sa" password=""
url="jdbc:sqlserver://localhost:1433;databaseName=asd" var="conn"/>
<sql:query var="login" dataSource="${conn}">
select * from tblUser where username =<c:out value="'${username}'" escapeXml="false"/>
</sql:query>
<c:forEach var="row" items="${login.rows}">
<c:if test="${row.password == password}">
<c:set var="loginsuccess" value="true"/>
</c:if>
</c:forEach>
<c:choose>
<c:when test="${loginsuccess=='true'}">
<c:set value="${username}" var="username" scope="session"/>
<c:redirect url="success.jsp"/>
</c:when>
<c:otherwise>
<c:redirect url="wrong.jsp"/>
<c:out value="${param.username}" escapeXml="false"/>
</c:otherwise>
</c:choose>
</body>
</html>