这样的功能能否实现?

ty4278 2003-04-04 09:34:51
WEB服务器1:在北京

WEB服务器2:在上海

WEB服务器3: 在西安

现在我想实现,把WEB服务器1作为登录验证服务器,也就是说在WEB服务器1登录以后再游览WEB服务器2和WEB

服务器3的jsp页面就无需再登录了,用java里面的技术,能否实现?多谢!
问题解决送500分
...全文
62 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
AllError 2003-04-04
  • 打赏
  • 举报
回复
没这样的东东
ty4278 2003-04-04
  • 打赏
  • 举报
回复
我是想当客户端关闭游览器时,该次写入的cookie自动过期!
ty4278 2003-04-04
  • 打赏
  • 举报
回复
哪些代码,是设COOKIE自动过期的?多谢了
aleccheung 2003-04-04
  • 打赏
  • 举报
回复
Cookie cookie = new Cookie(String name,String value);
request.addCookie(cookie);
set.MaxAge(int expiry);
AllError 2003-04-04
  • 打赏
  • 举报
回复
package com;

import java.io.PrintStream;
import javax.servlet.http.*;

public class CookieBean extends HttpServlet
{

public CookieBean()
{
}

public void addCookie(HttpServletResponse httpservletresponse, String s, String s1)
{
Cookie cookie = new Cookie(s, s1);
httpservletresponse.addCookie(cookie);
}

public int getCookieMaxAge(HttpServletRequest httpservletrequest, String s)
{
Cookie acookie[] = httpservletrequest.getCookies();
if(acookie != null)
{
for(int i = 0; i < acookie.length; i++)
if(acookie[i].getName().equals(s))
return acookie[i].getMaxAge();

}
return -1;
}

public String getCookieValue(HttpServletRequest httpservletrequest, String s)
{
String s2;
try
{
Cookie acookie[] = httpservletrequest.getCookies();
if(acookie != null)
{
for(int i = 0; i < acookie.length; i++)
if(acookie[i].getName().equals(s))
{
String s4;
try
{
String mm = acookie[i].getValue();
String s3 = mm;
return s3;
}
catch(Exception e)
{
s4 = "";
}
return s4;
}

}
String s1 = "";
return s1;
}
catch(Exception e)
{
s2 = "";
}
return s2;
}

public void setCookieMaxAge(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, int i)
{
Cookie acookie[] = httpservletrequest.getCookies();
if(acookie != null)
{
for(int j = 0; j < acookie.length; j++)
if(acookie[j].getName().equals(s))
{
acookie[j].setMaxAge(i);
httpservletresponse.addCookie(acookie[j]);
}

}
}

public void setCookieValue(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, String s1)
{
try
{
Cookie acookie[] = httpservletrequest.getCookies();
if(acookie != null)
{
for(int i = 0; i < acookie.length; i++)
if(acookie[i].getName().equals(s))
{
acookie[i].setValue(s1);
httpservletresponse.addCookie(acookie[i]);
}

}
}
catch(Exception e)
{
System.out.println("");
}
}
}

cookie的 javabean 设时间让它自动过期.

ty4278 2003-04-04
  • 打赏
  • 举报
回复
哇,多谢了!
这又有一个问题:在jsp中如何设COOKies,使得当用户关闭游览器时,自动把这个cookies删除!
老土豆T 2003-04-04
  • 打赏
  • 举报
回复
可以实现..
网易通行证就是这样实现的。

验证使用cookies... 不能用session.其他都差不多.

81,117

社区成员

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

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