为什么我不能通过在java servlet中使用out.println打印出任何东西?

时间:2016-06-13 13:50:57

标签: java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter(  ); 

        if(ServletFileUpload.isMultipartContent(request)){
            try {
                List<FileItem> multiparts = new ServletFileUpload(
                                         new DiskFileItemFactory()).parseRequest(request);

                for(FileItem item : multiparts){
                    if(!item.isFormField()){
                        String name = new File(item.getName()).getName();
                        item.write( new File(UPLOAD_DIRECTORY + File.separator + name));
                    }
                }               
            } catch (Exception ex) {
               out.println("File Upload Failed due to " + ex);
            }          

        }

2 个答案:

答案 0 :(得分:0)

你有没有尝试过:

out.println("File Upload Failed due to " + ex.getMessage());

out.println("File Upload Failed due to " + ex.printStackTrace());

答案 1 :(得分:0)

尝试使用doGet。

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.print("hey");
}