首先答案是:

会的。

本地测试流程:

两个相同的应用,代码完全相同;只是部署在两个不同的tomcat;域名都是localhost

应用A:部署在http://localhost:8087/

应用B:部署在http://localhost:8089/

在intelj idea中很简单,建立两个不同的运行配置即可:

步骤1:清空所有cookie

步骤2、在8087发送请求,用chrome开发工具查看

可以看到,生成了cookie。

用我的cookie扩展(名字叫editThisCookie),可以看到该cookie貌似没有区分端口号。

步骤3、在8089上测试一下

结论:可以看到,在请求8089端口的应用时,把8087应用返回的cookie带过去了,所以标题的答案就是:

同域名情况下,cookie同名同路径的话,会被覆盖(路径不同是否会覆盖没测试,有兴趣的同学自己测下)

参考资料
http://blog.csdn.net/wangjun5159/article/details/52399497

项目文件如下:

web.xml

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list> <!-- 登录过滤器 -->
<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
</web-app>
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException; /**
* Email: caokunliang@sgrcr.com
* Date: 2017/4/6
* desc:登录页面不进该filter
*/
public class SessionFilter extends OncePerRequestFilter { protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
String uri = httpServletRequest.getRequestURI();
System.out.println(uri);
if (uri.contains("login.jsp") || uri.contains("index.jsp") || uri.contains("session")){
filterChain.doFilter(httpServletRequest,httpServletResponse);
return;
} HttpSession session = httpServletRequest.getSession(false);
if (session == null){
//第一次访问,没带sessionid;下面的操作会默认创建一个session空间,并写cookie:jsessionid
session = httpServletRequest.getSession(true);
}else {
//不是第一次访问的话,已经有session空间了
System.out.println(session.getAttribute("SESSION"));
} //判断session空间中有没有登录标识
Boolean isLogin = (Boolean) session.getAttribute("isLogin");
if (isLogin != null && isLogin.equals(Boolean.TRUE)){
filterChain.doFilter(httpServletRequest,httpServletResponse);
}else {
//未登录
httpServletResponse.sendRedirect("/login.jsp");
}
} }

servlet:

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException; // tag::class[]
@WebServlet("/session")
public class SessionServlet extends HttpServlet { @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String attributeName = req.getParameter("attributeName");
String attributeValue = req.getParameter("attributeValue");
HttpSession session = req.getSession(false);
if (session == null){
session = req.getSession(true);
}
System.out.println("SessionServlet" + session.getAttribute("SESSION"));
if (attributeName.equals("ckl") && attributeValue.equals("123456")){
session.setAttribute("isLogin", Boolean.valueOf(true));
resp.sendRedirect(req.getContextPath() + "/index.jsp");
}else {
resp.sendRedirect(req.getContextPath() + "/login.jsp");
}
} private static final long serialVersionUID = 2878267318695777395L;
}

index.jsp

<!DOCTYPE html>
<html lang="en">
<title>Session Attributes</title>
<style type="text/css">
body {
padding: 1em;
}
</style> <head></head>
<body>
<div class="container">
<h1>Description</h1>
<p>index.jsp</p> <h1>Try it</h1> <div>登录成功后主页</div> <hr/> <table class="table table-striped">
<thead>
<tr>
<th>Attribute Name</th>
<th>Attribute Value</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>

login.jsp:

<!DOCTYPE html>
<html lang="en">
<title>Session Attributes</title>
<style type="text/css">
body {
padding: 1em;
}
</style> <head></head>
<body>
<div class="container">
<h1>Description</h1>
<p>login.jsp</p> <h1>Try it</h1> <form class="form-inline" role="form" action="./session" method="post">
<label for="attributeName">name</label>
<input id="attributeName" type="text" name="attributeName"/>
<label for="attributeValue">password</label>
<input id="attributeValue" type="text" name="attributeValue"/>
<input type="submit" value="Set Attribute"/>
</form> <hr/> <table class="table table-striped">
<thead>
<tr>
<th>name</th>
<th>password</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>

相同域名不同端口的两个应用,cookie名字、路径都相同的情况下,会覆盖吗的更多相关文章

  1. Tengine笔记2:通过IP、域名、端口实现虚拟主机

    一.通过端口创建虚拟主机 案例:通过端口访问两个不同的页面 将/usr/local/tengine-2.1.0/html/index.html内的内容改为 Welcom to port1 然后在/op ...

  2. tomact配置域名和端口直接访问网站

    tomact配置域名和端口直接访问网站,就是使用域名解析到主机,通过端口执行网站地址,实现访问,在上一章节中发布了两个web项目,但是都是执行同一个根文件夹,通过 http://localhost:8 ...

  3. .net core 启动域名及端口配置

    前两天转载一篇.net core 启动分析,由于发布时候一直纠结在默认5000端口上,所以好好研究了一下. 1.IIS集成 如果通过IIS当宿主的话,那这些都不是事情,强大的IIS可以帮助我们对站点的 ...

  4. C# System.Uri类_获取Url的各种属性_文件名_参数_域名_端口等等

    System.Uri类用于处理Uri地址信息,常用到它的地方有,相对Uri地址转绝对Uri地址,获取Uri的某部分信息等等,可以说是一个非常有用的类. 一.属性 AbsolutePath 获取 URI ...

  5. System.Uri类 - 获取Url的各种属性,文件名,参数,域名,端口等等

    System.Uri类用于处理Uri地址信息,常用到它的地方有,相对Uri地址转绝对Uri地址,获取Uri的某部分信息等等,可以说是一个非常有用的类. 一.属性 AbsolutePath 获取 URI ...

  6. nginx配置基于域名、端口、IP的虚拟主机

    1.基于域名的虚拟主机: 绝大多数企业对外提供服务的网站使用的都是基于域名的主机,通过不同的域名区分不同的虚拟主机. 首先我们进入安装nginxd的目录下:/application/nginx-1.6 ...

  7. 使用eclipse上Tomcat插件配置域名、端口号、启动时间详解

    作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7856284.html 邮箱:moyi@moyib ...

  8. Nginx配置基于多域名、端口、IP的虚拟主机

    原文:https://www.cnblogs.com/ssgeek/p/9220922.html ------------------------------- Nginx配置基于多域名.端口.IP的 ...

  9. nginx 域名绑定 域名, nginx 域名绑定 端口

    一.nginx 域名绑定 域名 nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件 ...

随机推荐

  1. C#判断某个类是否派生某个类或是否实现了某个接口

    is和as is关键字可以确定对象实例或表达式结果是否可转换为指定类型.基本语法: expr is type 如果满足以下条件,则 is 语句为 true: expr 是与 type 具有相同类型的一 ...

  2. Python基础-week04

    本节内容摘要:#Author:http://www.cnblogs.com/Jame-mei 装饰器 迭代器&生成器 Json & pickle 数据序列化 软件目录结构规范 作业:A ...

  3. 需求分析--WBS

    我们的软件天气预报的WBS如下:

  4. C++模板类与Qt信号槽混用

    一.正文 目前正在做一个视频处理相关的项目.项目的技术栈是这样的,UI层采用Qt来实现基本的数据展示和交互,底层音视频采用的是一套基于FFmpeg的视频处理框架.这是一套类似Microsoft Med ...

  5. 前端的UI设计与交互之设计原则篇

    1.亲密性 a)纵向间距示例这三种规格分别为:8px(小号间距).16px(中号间距).24px(大号间距). b)在这三种规格不适用的情况下,可以通过加减『基础间距』的倍数,或者增加元素来拉开信息层 ...

  6. 【深度学习】用PaddlePaddle进行车牌识别(二)

    上节我们讲了第一部分,如何用生成简易的车牌,这节课中我们会用PaddlePaddle来识别生成的车牌. 数据读取 在上一节生成车牌时,我们可以分别生成训练数据和测试数据,方法如下(完整代码在这里): ...

  7. 设计模式 --> (6)原型模式

    原型(Prototype)模式 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 原型模式是一种创建型设计模式,Prototype模式允许一个对象再创建另外一个可定制的对象,根本无需知 ...

  8. 理解HDFS

    综述 当数据集的大小超过一台独立的物理计算机的存储能力时,就有必要对它进行分区并存储到若干台单独的计算机上.HDFS是hadoop的主要分布式存储系统,一个HDFS集群主要包括NameNode用来管理 ...

  9. Git忽略规则.gitignore梳理

    对于经常使用Git的朋友来说,.gitignore配置一定不会陌生.废话不说多了,接下来就来说说这个.gitignore的使用. 首先要强调一点,这个文件的完整文件名就是".gitignor ...

  10. Struts存取数据

    ValueStack举例分析: Action存 Jsp页面取,用于数据展示 存数据三种方式总结 存数据->map 或 root 展示数据->Strusts标签   这个玩意用着很舒服,能让 ...