简体   繁体   中英

Jsp Multipart post method

I have two jsp pages, names are "insert.jsp" and "controller.jsp", i want to get file path from computer with "insert.jsp" , when i don't use "multipart" , i can't get file right path . But when i use "multipart" with method = "get" i get exception , if i use like this codes, i don't access in "controller.jsp".

Insert.jsp

<form  action = "controller.jsp"  enctype = "multipart/form-data"  method = "post">
            <table>                    
                <tr>
                    <td>Portrait Photo: </td>                        
                    <td><input type="file" name="namePhoto" size="50"/></td>    
                </tr>
            </table>
            <input type="submit" name="btnSaveInsert" value="Save"></td>

Controller.jsp

Enumeration paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();
        }
if (request.getParameter("btnSaveInsert") != null){
...
}

Multipart request has to be POST request. See this simple example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM