会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132436个问题
Python 全系列/第七阶段:网页编程基础/浮动与定位 4231楼
JAVA 全系列/第五阶段:JavaWeb开发/Ajax技术详解(旧) 4234楼

老师我这个代码第一遍跟着老师敲是没有问题的,我在另一个项目里面又试了一遍老是说我的post方法的enctype有问题,可是我设置了呀,老师我该怎么解决


Type 异常报告

消息 org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null

描述 服务器遇到一个意外的情况,阻止它完成请求。

Exception

javax.servlet.ServletException: org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
	org.apache.catalina.connector.Request.parseParts(Request.java:2913)
	org.apache.catalina.connector.Request.getParts(Request.java:2775)
	org.apache.catalina.connector.Request.getPart(Request.java:2944)
	org.apache.catalina.connector.RequestFacade.getPart(RequestFacade.java:1105)
	com.bjsxt.servlet.FileUpLoadServlet.doPost(FileUpLoadServlet.java:32)
	com.bjsxt.servlet.FileUpLoadServlet.doGet(FileUpLoadServlet.java:20)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
	org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:140)
	org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.getMultiPartStream(FileItemIteratorImpl.java:194)
	org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.findNextItem(FileItemIteratorImpl.java:213)
	org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.<init>(FileItemIteratorImpl.java:131)
	org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:255)
	org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:279)
	org.apache.catalina.connector.Request.parseParts(Request.java:2873)
	org.apache.catalina.connector.Request.getParts(Request.java:2775)
	org.apache.catalina.connector.Request.getPart(Request.java:2944)
	org.apache.catalina.connector.RequestFacade.getPart(RequestFacade.java:1105)
	com.bjsxt.servlet.FileUpLoadServlet.doPost(FileUpLoadServlet.java:32)
	com.bjsxt.servlet.FileUpLoadServlet.doGet(FileUpLoadServlet.java:20)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

):注意 主要问题的全部 stack 信息可以在 server logs 里查看


JAVA:

package com.bjsxt.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.UUID;

@WebServlet("/fileupload.do")
@MultipartConfig//基于注解开发的文件上传
public class FileUpLoadServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求编码
        req.setCharacterEncoding("utf-8");
        //设置响应编码
        resp.setContentType("text/html;charset=utf-8");
        //获取文件描述
        String desc = req.getParameter("desc");
        //获取part对象  参数给form表单中上传文件的name
        Part part = req.getPart("file");
        /*//设置唯一的文件名,避免因为文件名重复而造成文件覆盖,
        * 先截取文件的后缀(扩展名),然后与随机生成唯一的字符串拼接
        * UUID.randowUUID()随机生成一个唯一的字符串,返回UUID类型,需要调用toString()返回字符串类型*/
        String name = UUID.randomUUID().toString() + part.getSubmittedFileName().substring(part.getSubmittedFileName().lastIndexOf("."));
        //将相对路径转换为绝对路径
        ServletContext servletContext = this.getServletContext();
        String realPath = servletContext.getRealPath("images/" + name);
        System.out.println(realPath);
        //将上传的对象做IO流chuli,并通过字符输出流写入到路径中
        part.write(realPath);

        PrintWriter out = resp.getWriter();
        /*拼接HTML页面*/
        out.println("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>");
        out.println("<HTML>");
        out.println("<HEAD><TITLE>临江仙.文件上传</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("文件上传成功!"+desc);
        out.println("<BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }
}


HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body><!--
        get:以字符型方式提交,
        post:既可以以字节方式提交也可以字符方式提交
        -->
    <form   action="fileupload.do"  method="post"   enctype="multipart/form-data">
        文件描述:<input type="text" name="desc"/>
        文件上传:<input type="file" name="file"/>
        <input type="submit"   value="OK"/>
    </form>
</body>
</html>











JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 4235楼

<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:niNamespaceSchemaLocation="{book.xsd}">
    <book id ="1001">
        <name>java开发实战</name>
        <author>张小三</author>
        <price>98.5</price>>
    </book>>
</books>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="books">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="book" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                        <xs:element name="name" type="xs:string"></xs:element>
                        <xs:element name="author" type="xs:string"></xs:element>
                        <xs:element name="price" type="xs:double"></xs:element>
                        </xs:sequence>
                        <xs:attribute name="id" type="xs:positiveInteger" use="required"></xs:attribute>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
package com.Jin.XML;

import org.xml.sax.SAXException;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.File;
import java.io.IOException;

public class Test {
    public static void main(String[] args) throws SAXException {
        //(1)创建SchemaFactory工厂
        SchemaFactory sch = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        //(2)建立验证文件对象
        File schemaFile = new File("book.xsd");
        //(3)利用SchemaFactory工厂对象,接收验证的文件对象,生成Schema对象
        Schema schema = sch.newSchema(schemaFile);
        //(4)产生对此schema的验证器
        Validator validator = schema.newValidator();
        //(5)要验证的数据(准备数据源)
        Source source = new StreamSource("book.xml");
        //(6)开始验证
        try{
            validator.validate(source);
            System.out.println("成功");
        }catch (IOException e) {
            e.printStackTrace();
            System.out.println("失败");
        }

    }
}

显示找不到文件image.png

我看了之前过相同问题的,老师你回复idea要用绝对路径,我找了很久也不知道怎么弄,能说的仔细点吗

image.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/XML 技术(旧) 4237楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 4238楼

老师,这地方用set注入的时候,为什么这个属性一直报错呢?

image.png


下面是报错信息

F:\JDK\bin\java.exe "-javaagent:F:\ideaIU\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar=54117:F:\ideaIU\IntelliJ IDEA 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath "F:\JDK\jre\lib\charsets.jar;F:\JDK\jre\lib\deploy.jar;F:\JDK\jre\lib\ext\access-bridge-64.jar;F:\JDK\jre\lib\ext\cldrdata.jar;F:\JDK\jre\lib\ext\dnsns.jar;F:\JDK\jre\lib\ext\jaccess.jar;F:\JDK\jre\lib\ext\jfxrt.jar;F:\JDK\jre\lib\ext\localedata.jar;F:\JDK\jre\lib\ext\nashorn.jar;F:\JDK\jre\lib\ext\sunec.jar;F:\JDK\jre\lib\ext\sunjce_provider.jar;F:\JDK\jre\lib\ext\sunmscapi.jar;F:\JDK\jre\lib\ext\sunpkcs11.jar;F:\JDK\jre\lib\ext\zipfs.jar;F:\JDK\jre\lib\javaws.jar;F:\JDK\jre\lib\jce.jar;F:\JDK\jre\lib\jfr.jar;F:\JDK\jre\lib\jfxswt.jar;F:\JDK\jre\lib\jsse.jar;F:\JDK\jre\lib\management-agent.jar;F:\JDK\jre\lib\plugin.jar;F:\JDK\jre\lib\resources.jar;F:\JDK\jre\lib\rt.jar;E:\idea workplace\SpringDemo01\out\production\SpringDemo01;E:\JAR包\Spring\commons-logging-1.2.jar;E:\JAR包\Spring\spring-beans-5.2.7.RELEASE.jar;E:\JAR包\Spring\spring-context-5.2.7.RELEASE.jar;E:\JAR包\Spring\spring-core-5.2.7.RELEASE.jar;E:\JAR包\Spring\spring-expression-5.2.7.RELEASE.jar" com.bjsxt.test.DITest
八月 29, 2020 5:44:26 下午 org.springframework.context.support.ClassPathXmlApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersDao' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersDao' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
	at com.bjsxt.test.DITest.main(DITest.java:9)
Caused by: java.lang.IllegalStateException: No bean class specified on bean definition
	at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:436)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:68)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312)
	... 13 more

Process finished with exit code 1


JAVA 全系列/第六阶段:项目管理与SSM框架/Spring 4239楼
Python 全系列/第二十四阶段:人工智能基础_深度学习理论和实战(旧)/理解神经网络及应用 4240楼
Python 全系列/第十五阶段:Python 爬虫开发/爬虫基础(旧) 4241楼
Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 4243楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro 4244楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 4245楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637