单独写个JSP页面,判断是否为登录用户
<%@ page contentType="text/html; charset=utf-8" %>
<%
if(session.getAttribute("user")==null || session.getAttribute("user").toString().equals("")){
response.sendRedirect(request.getContextPath()+"/index.jsp");
return;
}
%>
上满的 return 必须要有,不然页面会继续执行下去,登录判断就没有意义了。。。。
在需要保护页面包含这个JSP即可:
<%include file="logincheck.jsp" %>
id 是浏览器用的, 比如 Javascript ,VBscript 使用 ID 来查找一个组件, Name 是提交给服务器那边 用的, 那边 CGI 或 Servlet 用 getParameter( "name ") 来查找提交过来的数据.所以 ID 要唯一, 不然,你总是只能找到排在前面的那组件, name 可以重复, 多个同名的组件用在像 Checkbox 组, 或者 多选列表.
<input name= "xx "> 会提交数据
<input id= "xx "> 不会提交数据
<input id= "xx " name= "yy ">
<label for= "xx "> Label </label> 这里的for属性必须是指向一个id,否则没效果
<input name= "xx " type= "radio " value= "1 ">
<input name= "xx " type= "radio " value= "2 ">
<input name= "xx " type= "radio " value= "3 ">
这里必须name相同才能成为一组单选按钮,而id则没有这个功能。
<input name= "xx "> 对应脚本document.getElementsByName( "xx ")[0]
<input id= "xx "> 对应脚本document.getElementById( "xx ")
区别还很多,不一一说了。反正这是两个完全不同的属性。不要混为一谈。