双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

springMVC过滤器过滤文件上传,获取参数为空

weixin_38066001 weixin_38066001 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
 开发四年只会写业务代码,分布式高并发都不会还做程序员?->>>    使用springMVC,图片上传,过滤器拦截获取不了请求参数。 页面发起的请求有三个参数:op,name,picture。 HTML代码如下: <form action="<%=request.getContextPath()%>/app" method="post" enctype="multipart/form-data"> op:<input name="op" value="user.regist" /><br/> 姓名(name):<input name="name" /><br/> 头像(picture):<input name="picture" type="file"><br/> <input type="submit"/> </form> 过滤器的实现的功能是获取op参数进行请求转发。 过滤器代码如下: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest)request; String op = httpRequest.getParameter("op"); op = op.replace(".", "/"); request.getRequestDispatcher("/app/"+op).forward(request, response); } 遇到的问题是表单的属性是enctype="multipart/form-data"时,过滤器取得的op值是null。 请教过滤器如何在表单属性enctype="multipart/form-data"时获取到op的值?是不是过滤器拦截到请求时表单还没有提交完毕,获取不了表单里面的值?求解决方案。
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部