在表单中使用multipart/form-data编码类型时,无法将参数传递给servlet [英] Cannot pass parameters to servlet when using multipart/form-data enctype in form

查看:59
本文介绍了在表单中使用multipart/form-data编码类型时,无法将参数传递给servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图传递来自嵌入在我的jsp文件中的文本编辑器的格式化文本.我在表单标签中使用enctype ="multipart/form-data".使用默认的enctype时,我可以将参数传递给servlet底层.但是在我的servlet中使用multipart/form-data编码时,我得到了null.

I m trying to pass formatted text from a text-editor that has been embedded in my jsp file. I m using enctype="multipart/form-data" in my form tag. I can pass the parameters to underyling servlet when using the default enctype. But I get null when using the multipart/form-data enctype in my servlet.

我的表格

<form action="pdfGenServlet" method="post" enctype="multipart/form-data">
                    <!-- input notes title-->
                    <div class="form-group">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Title of the notes" name="title">
                        </div>
                    </div>
                    <!-- input notes description-->
                    <div class="form-group">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Enter short description" name="description">
                        </div>
                    </div>

                    <div class="form-group">
                      <textarea name="content" id="myEditor"></textarea>

                     <div id="button-panel" class="panel panel-default">
                          <p>
                              <button type="submit" class="btn btn-primary "><span class="glyphicon glyphicon-plus"></span><strong> Create Note</strong></button>
                              <button class="btn btn-primary" type="reset"><strong>Reset</strong></button>
                          </p><!-- buttons -->
                     </div><!-- panel Button -->

                    </div>

                </form> 

我的pdfGenServlet.java

My pdfGenServlet.java

  @WebServlet("/pdfGenServlet")
 public class pdfGenServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      try {
            // Get the text that will be added to the PDF
            request.setCharacterEncoding("UTF-8");

            String title = request.getParameter("title");
            String description = request.getParameter("description");
            String notes_content = request.getParameter("content");
            Date date = new Date();
        } catch(exception e)
        {e.printStackTrace();}
      }

推荐答案

请参阅以下链接,它将帮助您上传带有输入参数的图像:

Refer to the following link it will help you to upload image with input parameters:

http://www.avajava.com/tutorials/lessons/how-do-i-upload-a-file-to-a-servlet.html

这篇关于在表单中使用multipart/form-data编码类型时,无法将参数传递给servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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