老师帮我看看,运行失败
package com.servlet; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; /** * */ public class RegistServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { // 1.创建一个磁盘文件工厂对象 DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); // 2.创建一个核心解析类 ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory); // 3.解析request请求,返回的是List集合,List集合中存放的是FileItem对象 List<FileItem> list = servletFileUpload.parseRequest(request); // 4.遍历集合,获得每个FileItem,判断是表单项还是文件上传项 for(FileItem fileItem : list) { //判断是表单项还是文件上传项 if(fileItem.isFormField()) { //普通表单项 //接收表单项参数的值 String name = fileItem.getFieldName();//获取表单的name属性的值 String value = fileItem.getString("UTF-8");//获取表单项的值 System.out.println(name+" "+value); }else { } } }catch(FileUploadException e) { e.printStackTrace(); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } ------------------------------------------------ <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>reg_login</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <display-name>InitServlet</display-name> <servlet-name>InitServlet</servlet-name> <servlet-class>com.servlet.InitServelt</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>InitServlet</servlet-name> <url-pattern>/InitServlet</url-pattern> </servlet-mapping> </web-app> --------------------------------------------------------------------- <%@ 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="/reg_login/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>
20
收起
正在回答 回答被采纳积分+1
2回答
chrismorgen
2018-06-27 19:02:16
你的RegistServlet没有在web.xml中注册,将下图代码添加到web.xml中问题就解决了,如果我的建议解决了你的问题,请采纳,祝学习愉快~
Java Web基础入门2018版
- 参与学习 716 人
- 提交作业 185 份
- 解答问题 1363 个
会Java?懂前端基础?想学后台开发?那么,赶快来学习《Java Web入门》路径吧。本路径主要介绍Java Web的基础知识,并配有大量案例,定会让你收获多多!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星