Java-返回附件响应后如何重定向到成功页面

时间:2019-08-13 14:43:22

标签: java redirect servlets

我正在尝试重定向到成功的jsp页面,同时从我的servlet返回附件响应(下载XML文件):

这是我的servlet代码:

try {
            String file = "File-"+year;

            JAXBContext jaxbContext = JAXBContext.newInstance(MyClass.class);           
            response.setContentType("text/xml; charset=UTF-8");
            OutputStream outStream = response.getOutputStream();

            javax.xml.bind.Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            jaxbMarshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
            jaxbMarshaller.marshal(myobject, outStream);
            response.setHeader("Content-Disposition", "attachment; filename="+file+".xml");
        //  response.sendRedirect("successp.jsp");

        } catch (JAXBException e) {
            e.printStackTrace();
        }

0 个答案:

没有答案