为了账号安全,请及时绑定邮箱和手机立即绑定

GWT 表单将 int 传递给 doGet() servlet

GWT 表单将 int 传递给 doGet() servlet

慕无忌1623718 2022-05-21 17:05:58
我使用 doGet() 方法向 servlet 提交表单。我需要的是通过 doGet() 将 id 传递给 servlet 并在该方法中检索它。到目前为止我尝试了什么:添加一个 id 作为查询字符串并在 doGet 中使用 request.getParameter()。我在 doPost() 及其工作中使用了相同的方法。客户端代码downloadPanel = new FormPanel();downloadPanel.setEncoding(FormPanel.ENCODING_MULTIPART);downloadPanel.setMethod(FormPanel.METHOD_GET);downloadPanel.setAction(GWT.getModuleBaseURL()+"downloadfile" + "?entityId="+ 101);downloadPanel.submit();  服务器端 servletpublic class FileDownload extends HttpServlet {private String entityId;public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {entityId = request.getParameter("entityId");entityId 为空。如何将 Id 传递给 doGet() 请求?至于在线查看示例,这应该可以正常工作,因为它适用于 doPost() 。谢谢,因为我很难过
查看完整描述

1 回答

?
浮云间

TA贡献1829条经验 获得超4个赞

操作字段中的查询参数被忽略(提交带有查询字符串参数和隐藏参数的 GET 表单消失)。您应该将其添加为隐藏参数(如何在 gwt 的 formPanel 上添加隐藏数据):


FormPanel form = new FormPanel();

form.setEncoding(FormPanel.ENCODING_URLENCODED); // use urlencoded

form.setMethod(FormPanel.METHOD_GET);

FlowPanel fields = new FlowPanel(); // FormPanel only accept one widget

fields.add(new Hidden("entityId", "101")); // add it as hidden

form.setWidget(fields); 

form.setAction(GWT.getModuleBaseURL() + "downloadfile");

form.submit(); // then the browser will add it as query param!

如果你不使用urlencoded它,它也可以使用request.getParameter(…),但它会在正文而不是 URL 中传输。


查看完整回答
反对 回复 2022-05-21
  • 1 回答
  • 0 关注
  • 129 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号