GWT 表单将 int 传递给 doGet() servlet
GWT form pass a int to a doGet() servlet
我使用 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();
服务器端 servlet
public 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() 原样。谢谢,因为我很困惑
操作字段中的查询参数被忽略 (submitting a GET form with query string params and hidden params disappear). You should add it as a hidden parameter ():
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。
我使用 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();
服务器端 servlet
public 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() 原样。谢谢,因为我很困惑
操作字段中的查询参数被忽略 (submitting a GET form with query string params and hidden params disappear). You should add it as a hidden parameter (
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。