Package javax.servlet.http

Examples of javax.servlet.http.Part


@WebServlet(name = "uploadServlet2", urlPatterns = "/upload2")
public class UploadServlet2 extends HttpServlet {

    @Override
    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        Part part = req.getPart("file1");
        //写到相对于 MultipartConfig中的location位置
        part.write("a.txt");
        //不保证多次调用成功,使用jetty测试时发现当调用多次,最后一次有效,即上传的文件会重命名为最后一次的文件名
        part.write("b.txt");

        //调用完InputStream记得关闭,否则删除不掉
        InputStream is = part.getInputStream();
        is.close(); //不能 part.getInputStream().close();//相当于多次获取
        //删除相关的文件
        part.delete();
    }
View Full Code Here


        //访问 /upload.jsp

        System.out.println(req.getParameter("name"));

        Part part = req.getPart("file1");
        //servlet 3.1 可以直接调用getSubmittedFileName得到客户端提交时的文件名
        System.out.println(part.getSubmittedFileName());
    }
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

    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

    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

    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

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

        Part warPart = null;
        String filename = null;
        String basename = 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

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.