0

그림을 업로드 할 수 있도록 Jquery 양식 플러그인을 사용하도록 코드를 변경했습니다. 내 원래의 형태는 그러나 지금은 내가 내 컨트롤러를 의미하는 가져도 요청을 따기되지 않은 400 잘못된 요청을받을Jquery Form Plugin을 사용할 때 400 잘못된 요청 받기

$.ajax({ 
    type: "POST", 
    url: "register.htm", 
    data:{ 
      account_name: $('#regAccount_name').val(), 
      pwd: MD5($('#regPwd').val()), 
      fname: $('#regFname').val(), 
      lname: $('#regLname').val(), 
    }, 
    success: function(data){ 
     changeMainIFrame('MenuFrame.jsp?regStatus=User Successfully Registered'); 
    }, 
    error:function(e){ 
     console.log("sendRegistration(): " + e); 
    } 

}); 

간단하지만,이

var options = { 
     beforeSend: function() 
     { 
      //alert(MD5($('#regPwd').val())); 
      // document.getElementById('regPwd').value = MD5($('#regPwd').val()); 

     }, 
     uploadProgress: function(event, position, total, percentComplete) 
     { 

     }, 
     success: function() 
     { 
      changeMainIFrame('MenuFrame.jsp?regStatus=User Successfully Registered'); 
     }, 
     complete: function(response) 
     { 
     }, 
     error: function(e) 
     { 
      console.log("sendRegistration(): " + e); 

     } 

    }; 

      $("#regForm").ajaxForm(options); 

로 변경되었습니다. 나는

@RequestMapping("/register.htm") 
public String register(// @RequestParam("regProfilePic") File pic, 
         @RequestParam("regAccount_name") String account_name, 
         @RequestParam("pwd") String pwd, 
         @RequestParam("fname") String fname, 
         @RequestParam("lname") String lname, 

         ModelMap params){ 

    setup(); 

    System.out.println("Register"); 
    service.registerUser(fname, lname, account_name, pwd); 

    return "MenuFrame"; 
} 

여기 여기 내 web.xml을

<?xml version="1.0" encoding="UTF-8"?> 
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>Volt</display-name> 

    <welcome-file-list> 
    <welcome-file>Mugenjou.jsp</welcome-file> 
    </welcome-file-list> 

    <session-config> 
     <session-timeout>30</session-timeout> 
    </session-config> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/classes/beans.xml</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <listener> 
     <listener-class> 
      org.springframework.web.context.request.RequestContextListener 
     </listener-class> 
    </listener> 

    <servlet> 
     <servlet-name>volts</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>volts</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 

    <jsp-config> 
     <taglib> 
      <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri> 
      <taglib-location>/WEB-INF/tld/c.tld</taglib-location> 
     </taglib> 
     <taglib> 
      <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri> 
      <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location> 
     </taglib> 
    </jsp-config> 
</web-app> 

그리고는 내 서블릿

<?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:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:component-scan base-package="com.mugenjou.control" /> 

    <!-- /WEB-INF/jsp/VIEWNAME.jsp --> 
    <bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <!-- <property name="prefix" value="/WEB-INF/jsp/"/> --> 
     <property value="" name="prefix"/> <property value=".jsp" name="suffix"/> 
    </bean> 


</beans> 

<form id ='regForm' action="register.htm" method="POST" enctype="multipart/form-data"> 

       <table cellpadding=5> 

        <!-- <tr> 
         <td>Profile Picture <br> <input type = "file" id ="regProfilePic" name ="regProfilePic" /></td> 
        </tr> --> 

        <tr> 
         <td> *Account Name <br> <input id ="regAccount_name" name = "regAccount_name" type="text" size ="20" onblur="isAccount_name();registerBtn();"/></td> 

         <td> 
          <div id ="chkUserLb"></div> 
         </td> 
        </tr> 

        <tr> 
         <td> *Password <br> <input id = "regPwd" name = "pwd" type="text" size ="20" onblur="isPwd();registerBtn();"/></td> 
         <td id=chkPwdLb></td> 
        </tr> 

        <tr> 
         <td> *First Name <br> <input id = "regFname" name ="fname" type="text" size ="20" onblur="isFname();registerBtn();"/></td> 
         <td id=chkFnameLb></td> 
        </tr> 

        <tr> 
         <td> *Last Name <br> <input id = "regLname" name = "lname" type="text" size ="20" onblur="isLname();registerBtn();"/></td> 
         <td id=chkLnameLb></td> 
       </tr> 


       <tr> 
        <td><input id = "regSubmitBtn" type="submit" value="Submit" disabled></td> 
       </tr> 

      </table> 

      *Required 

      </form> 

답변

0

문제를 찾은 HTML : 여기 내 컨트롤러 코드입니다 @RequestParam ("regProfilePi c ") File pic 대신 Multipart File pic