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

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

问题描述

我有一个使用 Apache Commons File Upload API 的Java EE应用程序.到目前为止,一切进展顺利,但我有一个疑问.

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.

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

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时一样.如果要传递参数,则应在<form>标记的属性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 ,则可以尝试如果您确实想通过URL传递,则${param}访问参数,而${attr}访问属性,如果使用 scriplets' getParameter. 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 Servlet和Commons FileUpload getParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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