String login=request.getParameter("login");
String pass=request.getParameter("pass");
VIP v=new VIPServer().Login(login);
if(v==null)
{
out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>");
return;
}
if(!v.getPass().equals(pass))
{
out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>");
return;
}
session.setAttribute("vip",v);
out.print("<script>location.replace('../index.jsp');</script>");
return;
这是登陆代码
除了<s:property/>外,一般标签是不认OGNL表达式的,必须加上%转换,不然会当成普通的字符串处理。
VIP是个类,里面存储了读取的所有字段,我试了你的方法还是不行,java怎么这么难搞,一个问题耗了我大半天
VIP是个类,里面存储了读取的所有字段,我试了你的方法还是不行,java怎么这么难搞,一个问题耗了我大半天'vip==null' 这个是想干嘛?
判断所有字段是不是为空?
VIP是个类,里面存储了读取的所有字段,我试了你的方法还是不行,java怎么这么难搞,一个问题耗了我大半天'vip==null' 这个是想干嘛?
判断所有字段是不是为空?想判断session是否为null,为null显示登陆,否则显示会员信息
试试
<
</s:if>
String login=request.getParameter("login");
String pass=request.getParameter("pass");
VIP v=new VIPServer().Login(login);
if(v==null)
{
out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>");
return;
}
if(!v.getPass().equals(pass))
{
out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>");
return;
}
session.setAttribute("vip",v);
out.print("<script>location.replace('../index.jsp');</script>");
return;下面这个是访问数据库的
public VIP Login(String login)
{
try
{
con=this.getcon();
String sql=String.format("select * from [VIP] where login='%s'",login);
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
VIP v=new VIP();
v.setId(rs.getInt("id"));
v.setXueli(rs.getString("XueLi"));
v.setLogin(rs.getString("login"));
v.setPass(rs.getString("pass"));
v.setName(rs.getString("name"));
v.setSex(rs.getString("sex"));
v.setAge(rs.getInt("age"));
v.setHobby(rs.getString("hobby"));
v.setShuoShuo(rs.getString("shuoshuo"));
v.setHeight(rs.getString("height"));
v.setHun(rs.getString("hun"));
v.setRegTime(rs.getDate("regTime"));
v.setImg(rs.getString("img"));
return v;
}
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeAll(con, ps, rs);
}
return null;
}
String login=request.getParameter("login");
String pass=request.getParameter("pass");
VIP v=new VIPServer().Login(login);
if(v==null)
{
out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>");
return;
}
if(!v.getPass().equals(pass))
{
out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>");
return;
}
session.setAttribute("vip",v);
out.print("<script>location.replace('../index.jsp');</script>");
return;下面这个是访问数据库的
public VIP Login(String login)
{
try
{
con=this.getcon();
String sql=String.format("select * from [VIP] where login='%s'",login);
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
VIP v=new VIP();
v.setId(rs.getInt("id"));
v.setXueli(rs.getString("XueLi"));
v.setLogin(rs.getString("login"));
v.setPass(rs.getString("pass"));
v.setName(rs.getString("name"));
v.setSex(rs.getString("sex"));
v.setAge(rs.getInt("age"));
v.setHobby(rs.getString("hobby"));
v.setShuoShuo(rs.getString("shuoshuo"));
v.setHeight(rs.getString("height"));
v.setHun(rs.getString("hun"));
v.setRegTime(rs.getDate("regTime"));
v.setImg(rs.getString("img"));
return v;
}
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeAll(con, ps, rs);
}
return null;
}我要看的是servlet整个 那个session是在哪定义的 懂不
<s:property value="#session.vip"/>
${vip}
没有取数据啊,session.vip==null,我没有从vip里面取任何数据啊
<% Mod.VIP v=(Mod.VIP)session.getAttribute("vip"); %>
<%=v.getLogin() %>这样可以读出来