0

I changed my code to using the Jquery Form Plugin so that I could upload pictures. My original form was simple

$.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);
    }

});

but changed to this

    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);

However now I get a 400 Bad Request which I take it to mean the my controller isn't even picking up the request. Here's my controller code:

    @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";
}

Here's My 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>

and here's my servlet

<?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>

the html

<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>
Raijin_x-u
  • 103
  • 1
  • 4
  • 15

1 Answers1

0

Found out the problem, I needed to use @RequestParam("regProfilePic") Multipart File pic instead of File pic

Raijin_x-u
  • 103
  • 1
  • 4
  • 15