Package javax.servlet.http

Examples of javax.servlet.http.Part


     * Otherwise, process it as UTF-8 bytes and return the equivalent String.
     */
    private static String slurpUtf8Part(HttpServletRequest request, HttpServletResponse response, String name, int maxLength)
            throws IOException, ServletException
    {
        Part part = request.getPart(name);
        if (part == null) {
            response.sendError(400, "Form field " + jq(name) + " is missing");
            return null;
        }

        byte[] bytes = new byte[maxLength];
        InputStream in = part.getInputStream();
        int bytesRead = in.read(bytes);
        String s = new String(bytes, 0, bytesRead, UTF8);
        if (in.read() != -1) {
            response.sendError(400, "Field " + jq(name) + " is too long (the limit is " + maxLength + " bytes): " + jq(s));
            return null;
View Full Code Here


            CommonsText.checkMaxLength(name, NAME_MAX_LENGTH, NAME_OVER_MAX_ERROR_MESSAGE);
            CommonsText.checkMaxLength(email, EMAIL_MAX_LENGTH, EMAIL_OVER_MAX_ERROR_MESSAGE);
            CommonsText.checkMaxLength(text, CONTENT_MAX_LENGTH, CONTENT_OVER_MAX_ERROR_MESSAGE);
            // 画像追加
            // <INPUT type="file" name="datafile"> で指定した名前より取得
            Part part = request.getPart("datafile");
            file  = CommonsBBS.uploadFile(part);
            // 投稿情報を追加
            Response addResponse =  new Response(time, name, text, email, file);
            ResponseManager resManager = new ResponseManager();
            // 追加成否による後処理
View Full Code Here

            CommonsText.checkMaxLength(name, CommonsBBS.NAME_MAX_LENGTH, CommonsBBS.NAME_OVER_MAX_ERROR_MESSAGE);
            CommonsText.checkMaxLength(email, CommonsBBS.EMAIL_MAX_LENGTH, CommonsBBS.EMAIL_OVER_MAX_ERROR_MESSAGE);
            CommonsText.checkMaxLength(text, CommonsBBS.CONTENT_MAX_LENGTH, CommonsBBS.CONTENT_OVER_MAX_ERROR_MESSAGE);
            // 画像追加
            // <INPUT type="file" name="datafile"> で指定した名前より取得
            Part part = request.getPart("datafile");
            file  = CommonsBBS.uploadFile(part);
          
            // 投稿情報を追加
            Response addResponse =  new Response(time, name, text, email, file);
            ResponseManager resManager = new ResponseManager();
View Full Code Here

            // 例外処理 (長すぎる場合 IOException)
            CommonsText.checkMaxLength(name, NAME_MAX_LENGTH, NAME_MAX_LENGTH_ERROR_MESSAGE);
            CommonsText.checkMaxLength(text, CONTENT_MAX_LENGTH, CONTENT_MAX_LENGTH_ERROR_MESSAGE);
            // 画像追加
            // <INPUT type="file" name="post_file"> で指定した名前より取得
            Part part = request.getPart("post_file");
            file  = uploadFile(part);
            // 投稿情報を追加
            Response addResponse =  new Response(time, name, text, CommonsText.ENPTY, file);
            ResponseManager resManager = new ResponseManager();
            boolean error = !resManager.add(addResponse);
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, ServletException {
        if (parts == null) {
            parseMultipart();
        }
        Part result = parts.get(name);
        if (result == null) {
            // FIXME: error message
            throw new ServletException();
        } else {
            return result;
View Full Code Here

    public String loadMarks() throws FenixServiceException, ServletException, IOException {
        final HttpServletRequest httpServletRequest =
                (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

        final Part fileItem = httpServletRequest.getPart("theFile");
        InputStream inputStream = null;
        try {
            inputStream = fileItem.getInputStream();
            final Map<String, String> marks = loadMarks(inputStream);

            WriteMarks.writeByStudent(getExecutionCourseID(), getEvaluationID(), buildStudentMarks(marks));

            return "success";
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

    }

    @Override
    public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException {
        if (submittedValue instanceof Part) {
            Part part = (Part) submittedValue;
            if ((part.getHeader("content-disposition") == null || part.getHeader("content-disposition").endsWith("filename=\"\"")) && part.getSize() <= 0) {
                return null;
            }
        }
        return submittedValue;
    }
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.