Package javax.servlet.http

Examples of javax.servlet.http.Part


            throw new RuntimeException("Wrong number of uploaded files. Expected 1 got " + files.size());
        }

        final User user = getUser(request);
        Authorizations authorizations = getAuthorizations(request, user);
        final Part file = files.get(0);
        String workspaceId = getActiveWorkspaceId(request);
        Workspace workspace = this.workspaceRepository.findById(workspaceId, user);

        Vertex entityVertex = graph.getVertex(graphVertexId, authorizations);
        if (entityVertex == null) {
View Full Code Here


        List<Part> files = toList(getFiles(request));
        if (files.size() != 1) {
            throw new RuntimeException("Wrong number of uploaded files. Expected 1 got " + files.size());
        }
        Part file = files.get(0);

        File tempFile = File.createTempFile("ontologyUpload", ".bin");
        writeToTempFile(file, tempFile);

        if (documentIRIString == null || documentIRIString.length() == 0) {
View Full Code Here

    protected String upload(HttpServletRequest request, StringManager smClient) {
        String message = "";

        try {
            while (true) {
                Part warPart = request.getPart("deployWar");
                if (warPart == null) {
                    message = smClient.getString(
                            "htmlManagerServlet.deployUploadNoFile");
                    break;
                }
                String filename = warPart.getSubmittedFileName();
                if (!filename.toLowerCase(Locale.ENGLISH).endsWith(".war")) {
                    message = smClient.getString(
                            "htmlManagerServlet.deployUploadNotWar", filename);
                    break;
                }
                // Get the filename if uploaded name includes a path
                if (filename.lastIndexOf('\\') >= 0) {
                    filename =
                        filename.substring(filename.lastIndexOf('\\') + 1);
                }
                if (filename.lastIndexOf('/') >= 0) {
                    filename =
                        filename.substring(filename.lastIndexOf('/') + 1);
                }

                // Identify the appBase of the owning Host of this Context
                // (if any)
                File file = new File(host.getAppBaseFile(), filename);
                if (file.exists()) {
                    message = smClient.getString(
                            "htmlManagerServlet.deployUploadWarExists",
                            filename);
                    break;
                }

                ContextName cn = new ContextName(filename, true);
                String name = cn.getName();

                if ((host.findChild(name) != null) && !isDeployed(name)) {
                    message = smClient.getString(
                            "htmlManagerServlet.deployUploadInServerXml",
                            filename);
                    break;
                }

                if (!isServiced(name)) {
                    addServiced(name);
                    try {
                        warPart.write(file.getAbsolutePath());
                        // Perform new deployment
                        check(name);
                    } finally {
                        removeServiced(name);
                    }
View Full Code Here

    protected String upload(HttpServletRequest request, StringManager smClient)
            throws IOException, ServletException {
        String message = "";

        Part warPart = null;
        String filename = null;

        Collection<Part> parts = request.getParts();
        Iterator<Part> iter = parts.iterator();
       
        try {
            while (iter.hasNext()) {
                Part part = iter.next();
                if (part.getName().equals("deployWar") && warPart == null) {
                    warPart = part;
                } else {
                    part.delete();
                }
            }

            while (true) {
                if (warPart == null) {
View Full Code Here

    public Part getPart(String name) throws IOException, IllegalStateException,
            ServletException {
        Collection<Part> c = getParts();
        Iterator<Part> iterator = c.iterator();
        while (iterator.hasNext()) {
            Part part = iterator.next();
            if (name.equals(part.getName())) {
                return part;
            }
        }
        return null;
    }
View Full Code Here

    public Part getPart(String name) throws IOException, IllegalStateException,
            ServletException {
        Collection<Part> c = getParts();
        Iterator<Part> iterator = c.iterator();
        while (iterator.hasNext()) {
            Part part = iterator.next();
            if (name.equals(part.getName())) {
                return part;
            }
        }
        return null;
    }
View Full Code Here

    public Part getPart(String name) throws IOException, IllegalStateException,
            ServletException {
        Collection<Part> c = getParts();
        Iterator<Part> iterator = c.iterator();
        while (iterator.hasNext()) {
            Part part = iterator.next();
            if (name.equals(part.getName())) {
                return part;
            }
        }
        return null;
    }
View Full Code Here

            message += "<p><b>HttpServletRequest.getParts() returns an empty collection!</b></p><br>";
        }       

        Throwable problem = null;
        try {
            Part p = ((HttpServletRequest) request).getPart("testFile");
            if (null != p) {
                String part = p.toString();
                String pname = p.getName();
                long size = p.getSize();
                String contentType = p.getContentType();
                String targetDirectory = ((HttpServletRequest) request).getServletContext().getRealPath("/test-3.0-servlet-war");
                if (size > 10000) {
                    message += "The file size is "
                            + size
                            + FILTERED_STRING + targetDirectory;
                } else {
                    message += "<font color=green><b>Part:</b> </font>"
                            + part
                            + "<br><font color=green><b>Part Name:</b> </font>"
                            + pname
                            + "<br><font color=green><b>Size:</b> </font>"
                            + size
                            + "<br><font color=green><b>ContentType:</b> </font>"
                            + contentType
                            + "<br><font color=green><b>HeadNames:</b> </font>";
                    for (String name : p.getHeaderNames()) {
                        message += name + ";";
                    }
                    java.io.InputStreamReader in = new java.io.InputStreamReader(
                            p.getInputStream());
                    String content = "";
                    int c = in.read();
                    while (c != -1) {
                        if (c == '\n') {
                            content += "<br>";
View Full Code Here

            //9.0.4.v20130625 已经修复了这个问题
            System.out.println(req.getParameter("name"));

            //获取Part部分
            System.out.println("\n\n==========file1");
            Part file1Part = req.getPart("file1")//只要调用 就会触发所有Part的上传
            InputStream file1PartInputStream = file1Part.getInputStream();
            System.out.println(IOUtils.toString(file1PartInputStream));
            file1PartInputStream.close();

            //如果多个 只获取第一个
            System.out.println("\n\n==========file2");
            Part file2Part = req.getPart("file2");
            InputStream file2PartInputStream = file2Part.getInputStream();
            System.out.println(IOUtils.toString(file2PartInputStream));
            file2PartInputStream.close();

            System.out.println("\n\n==========parameter name");
            //此时可以通过如下的一种得到表单数据
View Full Code Here

@WebServlet(name = "uploadServlet3", urlPatterns = "/upload3")
public class UploadServlet3 extends HttpServlet {

    @Override
    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        Part part = req.getPart("file1");
        InputStream is = part.getInputStream();
        System.out.println(IOUtils.toString(is));
        is.close();

        /**
         * jetty为例:
 
View Full Code Here

TOP

Related Classes of javax.servlet.http.Part

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.