Я новичок в Spring + MVN. У меня сейчас есть проект с контроллером, и я хочу «соединиться» со страницей JSP. Здесь у вас есть структура проекта:
У меня есть Web-servlet.xml, который содержит:
<beans xmlns = "http://www.springframework.org/schema/beans" xmlns:context = "http://www.springframework.org/schema/context" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" 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.ms.TicketsSystem" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
И web.xml:
<web-app id = "WebApp_ID" version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Form Handling</display-name> <servlet> <servlet-name>Web</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Web</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
Контроллер:
@Controller public class WebController { @RequestMapping(value="/add") public String addTicket(){ /* TODO */ return "add"; } }
И когда я иду к localhost:8080/add, это показывает
localhost:8080/add
Error resolving template [add], template might not exist or might not be accessible by any of the configured Template Resolvers
Есть предложения, что я делаю не так?
Ошибка шаблона Resolver предполагает использование Thymeleaf. Если вы не собираетесь использовать его, попробуйте отключить его в файле свойств приложения, используя spring.thymeleaf.enabled=false
spring.thymeleaf.enabled=false