今天自学到JSTL这,就跟着写写,写着写着有个问题一直没明白<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.java.model.*" %>
<%
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 'control.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>
<%
String uname=request.getParameter("username");
String pwd=request.getParameter("pass");
if(request.getParameter("post").equals("post")){
if(uname.equals("admin")&&pwd.equals("111")){
User user=new User();
user.setName(uname);
user.setPassword(pwd);
out.print("aaa");
request.getSession().setAttribute("user",user);
}else{
request.setAttribute("errMsg","用户名或密码不正确");
}
}
%>
<%!boolean isLogin; %>
<c:set var="user" value="${sessionScope.user}"></c:set>
<c:set var="isLogin" value="${not empty user}" scope="request"></c:set>
<%=isLogin %>
</body>
</html>
用TOMCAT运行,运行的时候输入正确的账号密码,为了好调试我输出三个a,但是不管怎么后面这个isLogin始终是false,
<%@ page import="com.java.model.*" %>
<%
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 'control.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>
<%
String uname=request.getParameter("username");
String pwd=request.getParameter("pass");
if(request.getParameter("post").equals("post")){
if(uname.equals("admin")&&pwd.equals("111")){
User user=new User();
user.setName(uname);
user.setPassword(pwd);
out.print("aaa");
request.getSession().setAttribute("user",user);
}else{
request.setAttribute("errMsg","用户名或密码不正确");
}
}
%>
<%!boolean isLogin; %>
<c:set var="user" value="${sessionScope.user}"></c:set>
<c:set var="isLogin" value="${not empty user}" scope="request"></c:set>
<%=isLogin %>
</body>
</html>
用TOMCAT运行,运行的时候输入正确的账号密码,为了好调试我输出三个a,但是不管怎么后面这个isLogin始终是false,
不行啊,我改成了SESSION 也是一样的