1

I'm new to spring, as well as spring mvc. I'm using version 3.1. Also, for now, I'm using Tomcat 7 and MySQL 5.5. I have data in a database table which I can display on a web page. Now, I'm trying to add data to my database from a web form, and then display that data on a web page.

Here is part of my runtime error when I try to invoke my web form:

** Root cause is: Request method 'GET' not supported org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.resolveHandlerMethod(AnnotationMethodHandlerAdapter.java:665) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:431) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at

Here is the section of my controller in question. Note, if I just have the @RequestMapping("/newProfile") line, instead of the other @RequestMapping line, then I get a web page, without my data showing, which is what I would expect, since I haven't plugged in my DAO layer just yet.

    @RequestMapping(value = "/newProfile", method = {RequestMethod.POST})
//@RequestMapping("/newProfile")
public String addNewProfile(@ModelAttribute("profile")Profile profile, ModelMap model) {
      model.addAttribute("firstName", profile.getFirstName());
      model.addAttribute("lastName", profile.getLastName());
      return "newProfileResult";
   }

Here is my input web form (using JSP for the moment):

<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>

<html>
<head>
    <title>Profile Test</title>
</head>
<body>

<h2>Information</h2>
<form:form method="POST" action="/newProfile">
   <table>
    <tr>
        <td><form:label path="firstName">First Name</form:label></td>
        <td><form:input path="firstName" /></td>
    </tr>
    <tr>
        <td><form:label path="lastName">Last Name</form:label></td>
        <td><form:input path="lastName" /></td>
    </tr>   
    <tr>
        <td colspan="2">
            <input type="submit" value="Submit"/>
        </td>
    </tr>    
</table>  
</form:form>
</body>

1 Answer 1

0

The Exception tells that Spring can't find a mapping for a GET request. I assume you enter just /newProfile into your browser. This causes a GET request. Provide a mapping to the GET request. You could do this by a separate mapping, or as you wrote ommit the method.

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

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.