httpservletrequest无法获取文件信息

时间:2019-03-15 01:10:01

标签: java file jsp tomcat file-upload

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Parallax Website Demo</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Gloria+Hallelujah" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
  
  <link rel="stylesheet" href="css/style.css">
  
</head>
<body>

<header class="main-header">
	

	<ul class="main-nav">
	<h1 class="name">The Purity of Css</h1>
	  <li><a class="active" href="#home">Home</a></li>
	  <li><a href="second-page.html">Inspiration</a></li>
	  <li><a href="second-page.html">Movie</a></li>
	  <li><a href="second-page.html">Other</a></li>
	  
	</ul>
	
</header>

<!--------------------------------------------------->
	<div class="pimg1">
		<div class="ptext font-2">
			<span class="border">
			 Where do you see yourself in 5 years?
			</span>
		</div>
	</div>


	<section class="section section-light">
		<h2>Section One</h2>
		<p>
		As HTML grew, it came to encompass a wider variety of stylistic capabilities to meet 
		the demands of web developers. This evolution gave the designer more control over 
		site appearance, at the cost of more complex HTML. Variations in web browser
		implementations, such as ViolaWWW and WorldWideWeb, made consistent site 
		appearance difficult, and users had less control over how web content was displayed.
		The browser/editor developed by Tim Berners-Lee had style sheets that were hard-coded into 
		the program. The style sheets could therefore not be linked to documents on the web.
		Robert Cailliau, also of CERN, wanted to separate the structure from the presentation so that 
		different style
		sheets could describe different presentation for printing, screen-based presentations, 
		and editors. - Wikipedea
		</p>
	</section>		

	

<!--------------------------------------------------->	
	
	
	<div class="pimg2">
		<div class="ptext">
			<span class="border trans font-2">
			 Will you be partying with friends?
			</span>
		</div>
	</div>
	
		<section class="section section-dark">
		<h2>Section Two</h2>
		<p>
		Tomorrowland is an electronic dance music festival held in Boom, Belgium. Tomorrowland was first held in 2005 and has since become one of the world's largest and most notable music festivals.
		It now stretches over 2 weekends and usually sells out in minutes. - Wikipedia
		</p>
	</section>	

	
	

<!--------------------------------------------------->	
	
	
	
	<div class="pimg3">
		<div class="text-1 ptext font-4">
			<span class="border trans">
			Traveling the world and living life?
			</span>
		</div>
	</div>
	
	<section class="section section-light">
		<h2>Section Three</h2>
		<p>
		Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut 
		labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 
		laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
		velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, 
		sunt in culpa qui officia deserunt mollit anim id est laborum.
		</p>
	</section>	

<!--------------------------------------------------->
	
	<div class="pimg4">
		<div class="ptext-2 font-5">
		
			<span class="border-2">
			  Or maybe following the footsteps of 
			 scholars before you
			</span>
			
		</div>
	</div>
	
	
<!--------------------------------------------------->
	
	
	<section class="section-light cool-image quick-fix">
		<h2 class="pict-1">A collection of beautiful places</h2>
		<p class="pict-2">
		Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut 
		</p>
		
	<img class="grid-1">	
	<img class="grid-2">
	<img class="grid-3">
	<img class="grid-4">
	<img class="grid-5">
	<img class="grid-6">
	
	
	</section>		
<!--------------------------------------------------------->

	
	
		<p class="pict-2">
		Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut 
		</p>
		
			<ol class="contacts">
			  <li>Head north on N Halsted St</li>
			  <li>Turn right on W Diversey Pkwy</li>
			  <li>Turn left on N Orchard St</li>
			</ol>

			<ol class="contacts-2">
			  <li>Head north on N Halsted St</li>
			  <li>Turn right on W Diversey Pkwy</li>
			  <li>Turn left on N Orchard St</li>
			</ol>

			<ol class="contacts-3">
			  <li>Head north on N Halsted St</li>
			  <li>Turn right on W Diversey Pkwy</li>
			  <li>Turn left on N Orchard St</li>
			</ol>

	

	
</body>

</html>

这是我在GroupAdd.jsp中的表单标签,我配置了entype =“ multipart / form-data”和方法类型POST。

<form id="groupAdd" name="groupAdd" method="POST" enctype="multipart/form-data"
    action="<c:url value='/group/groupAddProc.do'/>">
     ...
            <!-- File upload Start -->
            <tr>
                <td><spring:message code="group.chart" /></td>
                <td><input type="file" name="file" class="businessModText"></td>
            </tr>
 </form>

这是我的Groupcontorller.java文件,我有请求变量,而且我必须使用groupAdd方法将文件保存在项目路径中

这是我在GroupServiceImpl.java中的groupAdd方法

@RequestMapping(value = "/group/groupAddProc.do" , method = RequestMethod.POST )
public String groupAddProc(GroupVO vo, HttpServletRequest request, HttpSession session, Model model)
        throws Exception {
    if (!"yes".equals(session.getAttribute("adminLogin"))) {
        return "error/error";
    }
    int no = groupService.groupAdd(vo, request);
    groupVO.setNo(no);
    if (request.getParameterValues("addText") != null) {
        String[] result = request.getParameterValues("addText");
        for (String book : result) {
            groupVO.setBook(book);
            groupService.addBooks(groupVO);
        }
    }
    return "group/groupAdd";
}

在这种方法中,我还没有实现文件上传,但是我检查了请求变量是否包含文件内容。 但是结果是

请求没有文件内容:(

这个。

如何在请求变量中插入文件信息?

ps。我的请求变量除了文件信息外,还具有其他正确的信息。 (request.getParameter(“ file”)== null)

0 个答案:

没有答案