不知道为什么报错求解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | package com.servlet; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUpload; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; @WebServlet ( "/MVC_reg/RegistServlst" ) public class RegistServlet extends HttpServlet{ @Override protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { System.out.println( "start" ); try { DiskFileItemFactory diskFileItemFactory= new DiskFileItemFactory(); ServletFileUpload servletFileUpload= new ServletFileUpload(diskFileItemFactory); List<FileItem> list=servletFileUpload.parseRequest(arg0); for (FileItem fileItem:list) { if (fileItem.isFormField()) { String name=fileItem.getFieldName(); String value=fileItem.getString( "UTF-8" ); System.out.println(name+ " " +value); } else { } } } catch (FileUploadException e) { e.printStackTrace(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <%@ page language= "java" contentType= "text/html; charset=UTF-8" pageEncoding= "UTF-8" %> <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > <title>注册</title> <link rel= "stylesheet" href= "./css/reg.css" > </head> <body> <div class = "reg" > <div class = "header" > <h1> <a href= "./login.jsp" >登录</a> <a href= "./regist.jsp" >注册</a> </h1> </div> <form action= "/MVC_reg/RegistServlet" method= "post" enctype= "multipart/form-data" > <table> <tr> <td class = "td1" >用户名</td> <td><input type= "text" class = "input1" name= "username" ></td> </tr> <tr> <td class = "td1" >密码</td> <td><input type= "password" class = "input1" name= "password" ></td> </tr> <tr> <td class = "td1" >昵称</td> <td><input type= "text" class = "input1" name= "nickname" ></td> </tr> <tr> <td class = "td1" >性别</td> <td> <input type= "radio" name= "sex" value= "male" >男 <input type= "radio" name= "sex" value= "female" >女 </td> </tr> <tr> <td class = "td1" >上传头像</td> <td><input type= "file" id= "photo" name= "upload" ></td> </tr> <tr> <td class = "td1" >兴趣爱好</td> <td><label> <input type= "checkbox" name= "hobby" value= "篮球" >篮球 <input type= "checkbox" name= "hobby" value= "足球" >足球 <input type= "checkbox" name= "hobby" value= "排球" >排球 <input type= "checkbox" name= "hobby" value= "羽毛球" >羽毛球 </label></td> </tr> <tr> <td colspan= "2" > <div class = "btn-red" > <input type= "submit" value= "注册" id= "reg-btn" > </div> </td> </tr> </table> </form> </div> </body> </html> |
0
收起
正在回答 回答被采纳积分+1
1回答
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧