处理请求后的 Java Servlets 和 Commons FileUpload getParameter [英] Java Servlets and Commons FileUpload getParameter after Request being handle

查看:27
本文介绍了处理请求后的 Java Servlets 和 Commons FileUpload getParameter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Java EE 中有一个使用 Apache Commons File Upload API 的应用程序.到目前为止一切都很顺利,但我有一个问题.

I have an Application in Java EE using Apache Commons File Upload API. Everything is going smoothly so far but I have a question.

我在服务器端进行了某种验证 - 如果有任何问题,我必须将用户发送到上一页并将问题告知用户.此外,我必须将数据加载到表单中,但是当我在 JSP 中使用 request.getParameter("key") 时,它返回 null.

I have some kind of validation on the server side - if there is any problem I have to send the user to the previous page and inform the problem to the user. Also I have to load the data into the form, but when I use request.getParameter("key") in the JSP, it is returning null.

我已经对 commons-fileupload 未处理的请求进行了测试,我看到了结果.

I have tested with the request not being handled by commons-fileupload and I see the result.

我的问题是如何保留 request.getParameter("key") 并在请求由 org.apache.commons.fileupload.servlet 处理后将其发送回客户端.ServletFileUpload?

My question is how to keep the request.getParameter("key") and send it back to the client after the request is handled by org.apache.commons.fileupload.servlet.ServletFileUpload?

<%out.println(request.getParameter("cedula"));%> 请求被 API 处理后返回 null

<%out.println(request.getParameter("cedula"));%> returning null after request being handle by the API

推荐答案

1) 为什么使用 getParameter 而不是 getAttribute

1) Why do you use getParameter instead of getAttribute

2) 当验证错误发生时,请求被重定向,这意味着发送了一个新的请求对象,您需要再次提供请求属性.

2) When validation errors happen the request is redirected, this means a new request object is sent and you need to supply request attributes again.

与您在将操作分派到 JSP 时所做的相同.如果你想传递参数,那么你应该在

标签的属性 action 中提供它.

The same way you did it when the action is dispatched to JSP. If you want to pass the parameter then then you should supply it in the attribute action of the <form> tag.

似乎依赖于框架,但您可以尝试.注意,在 JSP 中如果你使用 EL 你可以试试${param} 访问参数和 ${attr} 访问属性,如果 scriplets' getParameter,如果你真的想通过 URL 传递它.JSTL 上还有好的艺术.

It seems framework dependent but you could try. Note, in the JSP if you use EL you can try ${param} to access the parameters and ${attr} to access attributes instead if scriplets' getParameter, if you really want to pass it via URL. There's also good art on JSTL.

这篇关于处理请求后的 Java Servlets 和 Commons FileUpload getParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆