是不是 URL 重写的问题?
解决方案 »
- Java 后台servlet编码的问题
- 初学, 请教二个问题。 路过的帮帮忙。
- 关于wap实现在线视频的技术
- 我做了一个小偷程序,现在能正确抓取网页了,可是图片却还在别人的服务器上,我想把图片也传到我的服务器,怎么作呢?
- 我把Tomcat整合到IIS里,不再需要8080端口来访问站点.但我的servlet还得用8080来访问,怎么办?
- 大菜鸟请高手指教:hibernate配置文件中参数的作用(高分相求)
- servlet可以通过url传参数吗?
- web 自动提交
- 真是郁闷 !折腾我好几天的问题 csdn 里 没有人回答
- 各位做JSP的结构如何?最近开发了几个JSP, 发现结构很有的玩
- JSP如何用JDBC直接连接interbase数据库,请高手帮忙。
- 如何通过session传递参数
<tr>
<td> </td>
<td><img src="images/user.gif" width="82" height="13"></td>
<td><input class="input1" type="text" name="user_name" value="admin"></td>
</tr>
<tr>
<td> </td>
<td><img src="images/passwordd.gif" width="82" height="13"></td>
<td><input class="input2"type="password" name="password" value="123456"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="56%"> </td>
<td width="44%"><input name="imageField" type="image" src="images/bttouu.gif"value="submit" width="46" height="18" border="0"></td>
</tr>
</table></td>
</tr>
</table>
</form>hand_login.jsp<%
Share_Connection conn = null; //建立连接
conn = Connection_Factory.Get_Bean_Share_Connection();
if(conn == null)
{
throw new Exception("得到数据库连接错误。。");
} String User_Name = request.getParameter("user_name");
String Password = request.getParameter("password"); Logon_Checker The_Logon_Checker = new Logon_Checker(); //SafeWord验证
Checker A_Checker = new SafeWord_Checker(conn);
The_Logon_Checker.Register(A_Checker); //登录限制
A_Checker = new Restrict_Checker(request,conn);
The_Logon_Checker.Register(A_Checker); User The_User = The_Logon_Checker.Check_User(User_Name,Password);
if(The_User == null)
{
throw new Exception(The_Logon_Checker.Get_Error_Msg());
}
The_User.Init_User_Info(session,conn);
if(conn != null)
{
conn.Real_Close();
}
session.setAttribute("User",The_User);/*User abc = (User)session.getAttribute("User");
out.print(abc.Get_User_Name());//在这里能取到session中的值
if (abc == null)
{
Gmcc_Exception e = new Gmcc_Exception("您还没有登陆!");
throw e;
}*/
response.sendRedirect("http://localhost:9080/app/index.jsp");
%>index.jsp
<%@ page import=" authentication.User" %>
<%@ page errorPage="login.jsp" %>
<%
User The_User = (User)session.getAttribute("User");//到这里就取值为null了
if (The_User == null)
{
Gmcc_Exception gmcc_e = new Gmcc_Exception("您还没有登陆!");
throw gmcc_e;
}
%>
login.jsp
<%@ page isErrorPage = "true" %>
<form method="post" action="Hand_Login.jsp"><table width="290" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td><img src="images/user.gif" width="82" height="13"></td>
<td><input class="input1" type="text" name="user_name" value="admin"></td>
</tr>
<tr>
<td> </td>
<td><img src="images/passwordd.gif" width="82" height="13"></td>
<td><input class="input2"type="password" name="password" value="123456"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="56%"> </td>
<td width="44%"><input name="imageField" type="image" src="images/bttouu.gif" width="46" height="18" border="0"></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td colspan="2" align="center"><%= exception.getMessage() %></td>
</tr>
</table>
</form>
为了方便大家看看,我把不必要的东东去掉了。
把这句话的地址该为相对地址
response.sendRedirect("./app/index.jsp");
由Login.htm->hand_login.jsp->index.jsp,无法在session里取得User
由Login.jsp->hand_login.jsp->index.jsp,可以在session里取得User
应该和跳转无关的不过在我的机器上没有出现这个问题啊
在hand_login.jsp页面检查过了,能得到东西,可到index.jsp就没了
可以用以下方法先校验以下:
1. hand_login.jsp以下代码:
User abc = (User)session.getAttribute("User");
out.print(abc.Get_User_Name());
改为:
out.print(session.getAttribute("User"));
2. index.jsp以下代码:
User The_User = (User)session.getAttribute("User");//到这里就取值为null了
改为:
out.print(session.getAttribute("User")); 如果现在index.jsp能取到session的值(我相信应该是这种情况),那就肯定可以说明是你的user类里面有问题了。打印调试一下user类里面的方法一定能解决。