NutzCN Logo
问答 http400错误(Bad REQUEST)
发布于 2477天前 作者 lqyounger 10500 次浏览 复制 上一个帖子 下一个帖子
标签: nginx

大神,看一下这个是什么问题吧,谢谢

package com.qf.action;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
@Controller
public class FileAction {
	@RequestMapping("/myFile.do")
	public String upFile(HttpServletRequest request, @RequestParam("myimg") MultipartFile multipartFile) throws IllegalStateException, IOException {
		// 1,得到文件的名称
		String name = multipartFile.getOriginalFilename();
		String newName = UUID.randomUUID() + name;
		File file =new File("F:\\Xiaomi"+newName);
		//3,把内存中的文件上传到指定的地方
		multipartFile.transferTo(file);
		return "index.jsp";

	}

}

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context.xsd   
        http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	<!--开启注解扫描 -->
	<context:component-scan base-package="com.qf.action"></context:component-scan>
	<!--开启注解标签,代替适配器和映射器 -->
	<mvc:annotation-driven></mvc:annotation-driven>
	<!-- 视图解析器 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean>
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="maxUploadSize" value="1024000"></property>
	</bean>
</beans>


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here






16 回复

HTTP Status [400] – [Bad Request]

Type Status Report

Message Required request part 'myimg' is not present

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Apache Tomcat/9.0.0.M21

网页重新发

这个可以上传图片吗,jsp页面有些代码没有上传成功

回复按钮旁边还有个按钮!!

<input type="file" 这个标签的name要等于‘myimg’

网页上面有两个按钮 回复 和 插入代码 这两个我都试了,都是上传jsp代码不全

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here






我猜的 ,看不到 你页面的代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="myFile.do" method="post" enctype="multipart/form-data">
		<input type="file" value="myimg">
		<input type="submit" value="上传图片">
	</form>

</body>
</html>

兽总,帮忙看一下吧

大神,是的,name ="myimg" ,问题解决了,谢谢了

<input type="file" name="myimg">

@hpuwanglei @wendal 因为我自己遇到过,所以一猜就中😬

来自炫酷吊炸天的 NutzCN

添加回复
请先登陆
回到顶部