1

I am getting the following warning: Request method 'POST' not supported.

Controller method:

@Controller
public class UserServiceController {

@RequestMapping(value = "/login", method = RequestMethod.POST)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public String login(@RequestParam Map<String,String> requestParams) throws Exception{
    System.out.println(requestParams.values());
    loginService.userAuthentication(requestParams.get("loginuname"), requestParams.get("loginpassword"));

    System.out.println("Before return");
    return "static/profile.html";
}
}

Dispatcher-servlet.xml

<mvc:resources mapping="/static/**" location="/WEB-INF/static/" />

index.html

<script language="javascript" type="text/javascript">
function submitForm(){
    document.login.submit();
}
</script>
<div id="login" class="login">   
<form action="http://localhost:8080/SampleApp/login" name="login" method="post">
      <input type="text" value = "Email" name="loginuname" id="loginuname" class="loginbasetxt">

      <input type="text" value="Password" name="loginpassword" id="loginpassword" class="loginbasetxt">
      <img src="static/img/tb-login-button.png" onclick="submitForm()"/>
</form>  
</div>

However, if i would change the method=RequestMethod.GET and correspondingly at login page then it would work.

Please note, problem is at return "static/profile.html";

FYI location of profile.html is WEB-INF/static/

Thanks!!

9
  • Get that warning where? And are you submitting the login information as request parameters in the POST or as a form? Commented Jan 21, 2014 at 12:37
  • are you sure your form's URL is correct and action attribute is action="POST"? Commented Jan 21, 2014 at 12:43
  • Please post the http form, the request that is sended, as well as the annotations next to the class keyword of your controller class. Commented Jan 21, 2014 at 12:48
  • could you please add some more code of Controller and jsp file or stack trace of error if you are getting on your console. Commented Jan 21, 2014 at 12:51
  • @chrylis getting HTTP Status 405 - Request method 'POST' not supported, on the browser.Yes, for the second query. Commented Jan 21, 2014 at 12:55

2 Answers 2

3

When you POST a form to an HTTP server, the form's contents aren't sent as query parameters; instead, the form is (usually) uploaded as an entity of type application/x-www-form-urlencoded. Instead of using @RequestParam in your method, define a Java class that has fields corresponding to the form fields, and use @ModelAttribute FormClass form.

Sign up to request clarification or add additional context in comments.

Comments

0

you should try this:

return "forward:/static/profile.html";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.