html代码
邮箱*
账号*
密码*
昵称*
介绍*
头像*
-----------------------------------------------------------------------------------
js代码:
<br> $(function () {<br> $("#btn").click(function () {</p> <pre><code> var f = $("#file").val(); if(f==null||f==""){ $("#picTip").html("<span style='color:Red'>错误提示:上传文件不能为空,请重新选择文件</span>"); }else{ var extname = f.substring(f.lastIndexOf(".")+1,f.length); extname = extname.toLowerCase();//处理了大小写 if(extname!= "jpeg"&&extname!= "jpg"&&extname!= "gif"&&extname!= "png"){ $("#picTip").html("<span style='color:Red'>错误提示:格式不正确,支持的图片格式为:JPEG、GIF、PNG!</span>"); } } adduser(); }); }); function adduser(){ var email=$("#email").val(); var account=$("#account").val(); var password=$("#password").val(); var nickname=$("#nickname").val(); var introduce=$("#introduce").val(); var formData = new FormData($("#uploadForm")[0]); alert(formData) alert(email) $.ajax({ url:"./zhuce", data:{"email":email,"account":account,"password":password,"nickname":nickname,"introduce":introduce,"formData":formData}, type:"post", async: false, cache: false, contentType: false, processData: false, success: function (data) { if(data=="error"){ alert("注册失败!") } if(data=="success"){ alert("成功!") window.location.href="login.jsp" } } }); } </script> ----------------------------------------------------------------------- </code></pre> <p>后台controller代码:<br> @RequestMapping(value="/zhuce")<br> @ResponseBody<br> public String zhuce(String email,String account,String password,String nickname,String introduce,@RequestParam(value="file",required = false) CommonsMultipartFile file,HttpServletRequest request, Model model){<br> System.out.println("邮箱和账号"+email+","+account);<br> System.out.println("hhhh");<br> System.out.println("filename:"+file.getOriginalFilename());</p> <pre><code> String path = request.getSession().getServletContext().getContextPath(); System.out.println("path:"+path); return "success"; } ---------------------------------------------------------------- </code></pre> <p>运行结果是:<br> 邮箱和账号null,null<br> hhhh<br> java.lang.NullPointerException--获取文件名字这里是空的</p>