There was an unexpected error (type=Method Not Allowed, status=405). SpringBoot на Tomcat сервере
Я только начал изучать HTTP, поэтому, возможно, мой вопрос покажется тупым, но все же хотелось бы получить на него ответ. У меня есть HTML страница:
<html>
<form name='test' method='post' action='http://localhost:8080/'>
<p><b>Фамилия:</b><br>
<input type='text' name='lastname' size='40'>
</p>
<p><b>Имя:</b><br>
<input type='text' name='firstname' size='40'>
</p>
<p>
<input type='submit' value='Отправить'>
</p>
</form>
</html>
А также некий код Spring Boot приложения:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HttpControllerREST extends HttpServlet {
@RequestMapping("/")
public String index(HttpServletRequest request, HttpServletResponse response) {
if (request.getParameter("lastname") != null || request.getParameter("firstname") != null) {
if (!request.getParameter("lastname").equals("") && !request.getParameter("firstname").equals("")) {
String lastname = request.getParameter("lastname");
String firstname = request.getParameter("firstname");
firstname = firstname.substring(0, 1);//Первая буква
return lastname + " " + firstname + ".";
} else
return "No POST data lastname or firstname";
}
return "Not POST data ";
}
}
Этот код подразумевает ввод в 2 окошка фамилии и имени пользователя, а в ответ получение фамилии с сокращенным именем. Я создал Spring Boot приложение в Eclipse, разместил HTML страницу в src/main/resources/static, запустил, зашел на localhost:8080, ввел данные, нажал отправить, но получил There was an unexpected error (type=Method Not Allowed, status=405).
В чем может быть ошибка? Подозреваю, что положил не туда HTML страницу.