关于防盗链的问题。

hexing_x 2008-07-16 05:29:52
login.jsp
<%@ page language="java" import="java.sql.*,javax.sql.*,com.admin.*"
pageEncoding="gbk"%>
<jsp:useBean id="useradmin" class="com.admin.dao.Unitsdao" scope="session"></jsp:useBean>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String type = null;
String sql = "select * from admin where username='" + username
+ "' and password='" + password + "'";
ResultSet rs = null;
rs = useradmin.executeQuery(sql);
if (rs.next()) {
type = rs.getString("type");
if (type.equals("manager")) {
session.setAttribute("username",username);
session.setAttribute("type",type);
response.sendRedirect("../CarInfo/Viewcarinfo.jsp");
} else if (type.equals("user")) {
session.setAttribute("username",username);
session.setAttribute("type",type);
response.sendRedirect("../CarInfo/Viewcarinfo.jsp");
}

} else {
out.print("<script>alert('密码或者用户名错误!请重新登录!');</script>");
response.sendRedirect("index.html");
}
%>

<html>
<head>
</head>
<body>
</body>
</html>
//防盗链
<%
String username=(String)session.getAttribute("username");
String type=(String)session.getAttribute("type").toString();
if(username==null){
response.sendRedirect("index.html");
}else{
out.print("你好,"+username+"欢迎登陆");
}
%>

为什么我不输入账号密码进去报空异常!!!!!
开始没做权限的时候,不输入账号密码点击其他页面都返回主页,而现在却直接报错
...全文
139 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hexing_x 2008-07-17
  • 打赏
  • 举报
回复
快下班的时候我自己搞出来了··谢谢大家
limon758 2008-07-17
  • 打赏
  • 举报
回复
关注一下
没搞过
zidasine 2008-07-17
  • 打赏
  • 举报
回复
if ("manager".equals(type)) {
session.setAttribute("username",username);
session.setAttribute("type",type);
response.sendRedirect("../CarInfo/Viewcarinfo.jsp");
} else if ("user".equals(type)) {
session.setAttribute("username",username
....
pilishou 2008-07-16
  • 打赏
  • 举报
回复
把报的错贴出来撒,谁知道是报什么错呢......

为什么我不输入账号密码进去报空异常!!!!!
做系统开发肯定需要对表单进行验证的,不允许关键输入项为空。没有输入,查出来的东西自然为空,所以报空指针,靠的住的。
hexing_x 2008-07-16
  • 打赏
  • 举报
回复
如果我去掉String type=(String)session.getAttribute("type").toString();
就能正常显示加上则会出现空异常
hexing_x 2008-07-16
  • 打赏
  • 举报
回复
下班了··明天来看·
hexing_x 2008-07-16
  • 打赏
  • 举报
回复
<%
String username=(String)session.getAttribute("username");
String type=(String)session.getAttribute("type").toString();
if(username==null){
response.sendRedirect("index.html");
}else{
out.print("你好,"+username+"欢迎登陆");
}
%>
这就是判断撒··
jayray007 2008-07-16
  • 打赏
  • 举报
回复
做一个判断
如果帐号和密码只要有一个为空
就不跳转

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧