Cannot expose request attribute 'userName' because of an existing model object of the same name

OpenClaw 在 Windows 环境下的完整安装、配置和部署指南 介绍Windows环境下OpenClaw的完整安装,配置和部署的全流程 阅读详情

一、背景说明

     在预发布环境中进行功能验证时,点击“我的反馈”菜单时出现Cannot expose request attribute 'userName' because of an existing model object of the same name 错误,在测试环境正常显示。

二、认识异常

11-Jun-2019 16:43:57.429 SEVERE    org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [springServlet] in context with path [] threw exception [Cannot expose request attribute 'userName' because of an existing model object of the same name] with root cause
javax.servlet.ServletException: Cannot expose request attribute 'userName' because of an existing model object of the same name
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:123)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

错误异常说明:request中存在同名的userName属性,获取失败
注:该错误会在Tomcat的server/logs/localhost.log日志中展示

三、排查问题

1、在LoginInteceptor中通过 request.setAttribute 方式添加了userName属性

public class LoginInteceptor implements HandlerInterceptor{
    @Override
    boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
	    throws Exception{
        /**......**/
	request.setAttribute("userName",'test');
	/**......**/
    }
}

2、同时在Controller中通过modelAndView.addObject 方式添加了userName属性

@RequestMapping("/myCall")
public ModelAndView myCall(ModelAndView modelAndView){
	modelAndView.setViewName("my/call");
	modelAndView.addObject("userName","test");
	return modelAndView ;
}

3、同时在Spring MVC的viewResolver解析器中配置了exposeRequestAttributes和exposeSessionAttributes值为ture

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
	/**......**/
	<property name="exposeRequestAttributes" value="true"/>
	<property name="exposeSessionAttributes" value="true"/>
	/**......**/
</bean>

exposeRequestAttributes 和 exposeSessionAttributes 设置为true的话会将request和session中的键值和值合并到modelAndView的Map参数中。

通过以上三项最终导致问题的产生

四、解决问题

方案一:修改Controller中参数名称userName,改为modelAndView.addObject("myUserName","test"),简单粗暴

方案二:在Spring MVC的viewResolver解析器配置中添加allowRequestOverride=true和allowSessionOverride=true配置,允许request和session设置的键值被覆盖,具体配置如下所示:

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
	/**......**/
	<property name="exposeRequestAttributes" value="true"/>
	<property name="allowRequestOverride" value="true"/>
	<property name="exposeSessionAttributes" value="true"/>
	<property name="allowSessionOverride" value="true"/>
	/**......**/
</bean>

注:两种方案都可以解决Cannot expose request attribute 'userName' because of an existing model object of the same name 问题

Claude Code 处理长任务 + Cursor 专注交互:双栈协作的 3 种分工场景与响应提速 35% 实测 揭示 Claude Code 与 Cursor 在 AI 编程中的本质分工:Claude Code 作为离线式架构师处理跨文件、带约束的长链路重构(如单体拆微服务),Cursor 作为现场交互工程师专注秒级局部编辑;提出按任务切片动态切换的三种工程化协作场景,并给出结构化上下文构建、约束型 Prom 阅读详情

相关推荐

SAP IDOC实战:如何用EDI实现跨公司采购订单自动生成销售订单(附完整配置步骤)

本文详细解析了如何利用SAP IDOC与EDI技术,实现跨公司采购订单自动生成销售订单的完整流程。通过实战案例,从业务蓝图设计、输出条件配置、伙伴参数设定到IDOC消息类型处理,提供了清晰的配置步骤与故障排查指南,帮助企业打通内部业务流,构建高效的自动化闭环。

weixin_29215815的博客 728

freemarker 异常:Cannot expose request attribute 'request' because of an existing

使用freemarker模板技术的项目,访问服务器异常 javax.servlet.ServletException: Cannot expose request attribute 'request' because of an existing model object of the same name at org.springframework.web.servlet.view...

java中equals和==的区别!!! 2105

Camera 基础知识

Raw Sensor输出的Data格式为Raw,图像的效果处理使用BB端的ISP,BB端接收Raw data后进行一系列的图像处理(OB,Shading,AWB,Gamma,EE,ANR等),效果方面由BB端控制,需要针对不同的模组进行效果调试,Raw sensor是目前的主流,数据量比YUV Sensor小(RAW10 格式的sensor 1个pixel 10个bit)使用平台ISP处理,能支持较大的size。不过,相位对焦并不是那么完美,它对光线的要求就比较高,在弱光拍摄环境下,相位对焦就无能威力了。

手机-手表蓝牙开发工程师的博客 3062

SpringMVC生成VM或FreeMarker时处理Model属性报错分析

出错现象 近期在维护一个使用vm作为页面视图的项目时,遇到过这样一个错误。 org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [springServlet] in context with path [/portal-web] threw exception [C...

kaka0509的专栏 1158

华为OD机试双机位C卷-员工派遣(Py/Java/C/C++/Js/Go)

华为OD机试双机位C卷【员工派遣】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。华为OD机试- 员工派遣,华为OD机考 - 员工派遣。

qq_45776114的博客 1671

【异常】Coze/扣子 Workflow 调用报 4200 错误深度解析

Coze API 的。

奶爸的编程之路,也就一周冷个三天 301

because of an existing model object of the same name

背景:   视图解析器(我们用的是velocity) 报错:   because of an existing model object of the same name 按照网上给的原因 : 设置了属性exposeSessionAttributes为true之后,所有的session中的变量都会在传给视图(velocity模板)时被合并到model中。这时如果在控制器中使用了@ses...

weixin_30924239的博客 578

8.26华为OD机试真题 新系统 - 字符串回文判 (Java/Py/C/C++/Js/Go)

8.26华为OD机试真题 新系统 - 字符串回文判 (Java/Py/C/C++/Js/Go)

算法大师! 1231

Spring采用视图时,使用@SessionAttributes("")注解出现异常

Spring采用视图时,使用@SessionAttributes("")注解出现Cannot expose session attribute 'user' because of an existing model object of the same name异常问题 错误原因: 因为request session默认是不会加入velicity context中的,所以要配置上 expo...

Asa_Prince的博客 565

【python数据处理】python实现vlookup字符串模糊匹配及在实战中的应用(FuzzyWuzzy库)

利用FuzzyWuzzy库匹配字符串1. 背景前言2. FuzzyWuzzy库介绍2.1 安装2.1 fuzz模块2.1.1 简单匹配(Ratio)2.1.2 非完全匹配(Partial Ratio)2.1.3 忽略顺序匹配(Token Sort Ratio)2.1.4 去重子集匹配(Token Set Ratio)2.2 process模块2.2.1 extract提取多条数据2.2.2 extractOne提取一条数据3. pandas实战应用3.1 公司名称字段模糊匹配3.1.1 参数讲解:3.1.2

lys_828的博客 8322

2026年紫光同创数字IC笔试试卷带答案

FPGA基础知识与设计要点摘要 本文围绕FPGA与数字IC设计核心概念,通过单选题、波形分析题、多选题和简答题形式,系统梳理了以下关键知识点: FPGA基础架构 查找表(LUT)是实现组合逻辑的基本单元(题1) CLB包含LUT、触发器和进位链,后者加速算术运算(题6,10) 布局布线优化是减少关键路径延迟的核心方法(题7) 时序分析要点 建立时间(时钟沿前数据需稳定)与保持时间(时钟沿后需保持)的定义(题2,简答1) 亚稳态成因及两级同步器处理跨时钟域信号的方法(多选题1,波形题5) 特殊设计技术 异步复

Open 114

juju reactive charm (by quqi99)

sudo snap install charm --classic mkdir -p /bak/work/charms/layers export JUJU_REPOSITORY=/bak/work/charms export LAYER_PATH=$JUJU_REPOSITORY/layers cd $LAYER_PATH charm create simple cd simple sudo ...

技术并艺术着 8718

2025华为OD 面试手撕代码真题【字符串至多删除一个字符,是否能构成回文串】

2025华为OD 面试手撕代码真题【字符串至多删除一个字符,是否能构成回文串】

MISAYAONE的博客 1705

springboot出现Cannot expose session attribute 'user' ,existing model object of the same name

问题描述:在做Springboot项目的时候出现如下错误 javax.servlet.ServletException: Cannot expose session attribute 'user' because of an existing model object of the same name 前端模板用的是freemarker,解决方法如下:   我们除了在pom.xml里面导...

pengge0727的博客 1392

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

springBoot - 异常 - Cannot expose session attribute 'user' because of an existing model object of the

分析: 开启:设置是否允许HttpSession属性覆盖 异常:Cannot expose session attribute 'user' because of an existing model object of the same name 异常:javax.servlet.ServletException: Cannot expose session attribute 'user'...

阿泷的学习日志 4613

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Cannot expose session attribute because of an existing model object of the sa

在开发中,就一个 对象 放入了 session里面 在 使用 freeemarker 的时候,就 另一个对象,以同样的名称 放入 modeandview 里面 结果就出错了,所以以后 这样 呢就不要 和 session的内容属性 重名,也尽量少使用session 来搞事 ...

chuncui2576的博客 386

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

SpringBoot启动项目报错: Cannot expose session attribute 'user' because of an existing model object of the

报错:Cannot expose session attribute 'user' because of an existing model object of the same name javax.servlet.ServletException: Cannot expose session attribute 'user' because of an existing model o...

懒惰的小妖 1771

cannot expose session attribute '_from_source' because of an existing model object of the same name

启动不报异常,访问报此异常: cannot expose session attribute '_from_source' because of an existing model object of the same name

cm_0914的专栏 6112

Spring采用velicity视图时,使用@SessionAttributes("")注解出现Cannot expose session attribute 'user' because of an

Spring采用velicity视图时,使用@SessionAttributes("")注解出现Cannot expose session attribute 'user' because of an existing model object of the same name异常问题 错误原因: 因为request  session默认是不会加入velicity context中

ytp151730的专栏 4210

Request 认识

文章目录一、request 对象和 response 对象的原理二、request对象继承体系结构 一、request 对象和 response 对象的原理 (1)request 和 response 对象是由服务器创建的,我们来使用它们 (2)request 对象是来获取请求消息,response 对象是来设置响应消息 二、request对象继承体系结构 ServletRequest --...

南淮北安的博客 393

springMacroRequestContext定义

最近一直想知道springmvc中的zhspringMacroRequestContext

fendou4533的专栏 1万+

网上关于FreeMarker的三宗罪之争~~~

FreeMarker是Quake Wang推荐我使用的。刚学FreeMarker的时候,发现freemarker真的很棒!简单易用,功能强大。但是用它做了几个项目以后开始不爽了。 一宗罪:freemarker的变量必须有值,没有被赋值的变量就会抛出异常,那个黄黄的freemarker出错页面,真是让人看了太难过了。 freemarker的FAQ上面冠冕堂皇的说,未赋值的变量强制抛错可以杜...

haiker 247

#springMessage 错误分析

在 项目中使用#springMessage进行错误码解析为错误消息,可是在特定的场景下出现了       $springMacroRequestContext.getMessage($code)   #springMessage      是在org/springframework/web/servlet/view/velocity/spring.vm 文件中定义了一个宏。其内容是: ...

技术分享 928
上一篇: getOutputStream() has already been called for this response 从了解到解决
下一篇: 使用JDK1.8 parallelStream 引发的 Lock wait timeout exceeded; try restarting transaction
TimerBin
博客等级 码龄12年 54粉丝 119原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值