- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在做一些非常简单但不起作用的事情。
我有一个带有按钮的 html 页面,该按钮应该注销并删除登录 cookie,按下时,它/在 servlet 中运行此代码:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
deleteCookie(req, resp);
resp.sendRedirect("login");
}
private void deleteCookie(HttpServletRequest req, HttpServletResponse resp) {
Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (CID_KEY_NAME.equals(cookie.getName())) {
cookie.setMaxAge(0); // Should make the browser delete the cookie
cookie.setValue(null);
resp.addCookie(cookie);
}
}
}
}
sendRedirect("login")
将我发送到负责登录的新 servlet,但是当我到达新 servlet 并检查上面的 cookie 是否存在时,我可以看到它存在,maxage 值为 -1
我做错了什么吗?
最佳答案
根据 HTTP Cookies: What's the difference between Max-age and Expires? ,至少 Internet Explorer 6、7 和 8 不支持 Max-Age
,但支持 Expires
。如果这是你的问题,那么我会尝试将这两个设置为:
Q. What if I set both expires and max-age in a cookie?
A. Every browser that supports max-age will ignore the expires regardless of it’s value, and likewise, Internet Explorer will ignore the max-age and just use expires.
该页面还有一个指向 cookie persistence test page 的链接您可能会觉得有用。
关于java - 在 HTTPServlet doPost() 中将 maxage(0) 设置为 cookie 并且重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8562256/
我被告知这不是一个好的做法 @Autowired HttpServlet httpServlet; 在 Spring Boot 中,因为它只会为所有点击创建一个对象。我对 Spring Boot 和
我想知道反序列化后是否调用了 HttpServlet 的 init 方法。 我不知道是否有任何容器曾经序列化一个 servlet,但它实现了 Serializable 接口(interface),所以
我在 HttpServlet 文档中读到 HttpServlet 的子类必须重写至少一个方法,通常是以下方法之一: doGet, if the servlet supports HTTP GET re
我有几个在服务器端执行操作的 servlet。在一些上,我只是编码一些不必要的数据并将其发送回来,这似乎毫无意义。你必须回应吗?当您只说 return 时会发生什么?我以前这样做过,似乎没有什么问题,
我尝试创建一个文件,写入文件,然后将文件转换为输入流,并将其字节传输到 HTTP 响应的输出流。但我收到消息“/tmp/mozilla_xxxx/33JJ1OHw.md.part 无法保存,因为无法读
我正在开发一个具有两个 Web 界面的 Java 应用程序:一个处理某些 Web 服务逻辑的 servlet (/WSProxy) 和一个使用 Spring 框架的 Web 管理界面(/Admin 或
我在 Java EE 应用程序中使用 Apache Tomcat v8.0 服务器。基本上,我创建了一个 ResponseUpload servlet。我需要通过 POST 请求从 Web 应用程序获
这个问题在这里已经有了答案: How many instances are created for a HTTP servlet (2 个答案) 关闭 6 年前。 根据servlet的生命周期,se
我有一个 Web 应用程序,其中多个 servlet 使用一定数量的相同逻辑进行预初始化(设置日志记录、 session 跟踪等)。我所做的是在 javax.servlet.http.HttpServ
我有一个应用程序,用户正在访问 servlet 文件,该文件将有条件地读取 .pdf 文件并发送 .pdf 文件作为对用户请求的响应。 servlet 代码不会设置响应 header 的内容长度。 在
这个问题在这里已经有了答案: Http Servlet request lose params from POST body after read it once (13 个答案) 关闭 7 年前。
基本上,一个 servlet 实例存在多长时间?我有点猜测它是 session 范围。但是,我想它可能有某种超时或垃圾收集来删除旧实例。 最佳答案 当应用程序启动时(部署在 servlet 容器上)或
我需要一些帮助,我的意思是对这个继承设计的意见。 我创建了Controller.class,它扩展了HttpServlet和AjaxController.class 扩展了 Controller.cl
我想在扩展 HttpServlet 的类上注入(inject) DAO 依赖项,这可能吗?我不想从应用程序上下文中手动获取依赖项,但如果可能的话,希望在我的 Servlet 实例上进行真正的依赖项注入
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
假设,我有一个 TestServlet 类,它声明为全局字符串变量。如果同时调用 TestServlet 类,则此“消息”字符串变量是否可以安全地打印而无需从并发线程交叉? public class
我有一个扩展 HttpServlet 类的类。我知道 Java 是多线程的,不同的线程(阅读:HTTP 请求)可以使用同一个实例。我想在第一个请求时实例化一个对象并使用它直到 session 结束。
出于记录目的,我重写了 HttpServlet 的服务方法,如下所示: @Override protected void service(HttpServletRequest req, HttpSer
我对在 Google App Engine 上遇到的这个问题感到困惑。 我创建了几个servlet,因此我创建了一个基类来完成一些基本的重复工作。像这样: public class MyBase ex
我想用 http://www.easymock.org/ 测试我的 servlet 如何编写单元测试代码? 我根据您的回复更新我的代码。 我刚刚使用 Google 并制作了这段代码。 这是我的 Ser
我是一名优秀的程序员,十分优秀!