--------------------------------------------------------------------------------
This is my LoginController
--------------------------------------------------------------------------------
@Controller
public class LoginController {
public static final String STATUS_MESSAGE = "STATUS_MESSAGE";
@RequestMapping(value = "/", method = RequestMethod.GET)
public String showLoginView() {
return "login";
}
@RequestMapping(value="/logincredentials", method=RequestMethod.GET)
public String showLoginCredentials() {
return "logincredentials";
}
@RequestMapping(value="/logincredentials", method=RequestMethod.POST)
public String login(Model model, @ModelAttribute("nif") String nif, @ModelAttribute("usercode") String usercode, @ModelAttribute("pass") String pass, HttpServletRequest req) throws IOException { // model.addAttribute("loginForm", new LoginForm()); //
System.out.println("nif = " + nif);
System.out.println("usercode = " + usercode);
System.out.println("pass = " + pass);
// Get the web application context, all spring beans are managed in this context.
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(req.getServletContext());
UserAccountBean userAccountBean = (UserAccountBean)context.getBean("userAccountBean");
boolean checkResult = userAccountBean.checkUserLogin(nif, usercode, pass);
if(checkResult)
{
model.addAttribute(STATUS_MESSAGE, "User account is correct. ");
return "home";
}else
{
model.addAttribute(STATUS_MESSAGE, "User account is not correct. ");
return "login";
}
}
}
------------------------------------------------------------------------------
This is my web.xml
------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<element>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
id="WebApp_ID" version="4.0">
<display-name>IEVweb_v2</display-name>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods"
value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/application-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>quiz</servlet-name>
<jsp-file>quiz.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>quiz</servlet-name>
<url-pattern>/quiz</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>home</servlet-name>
<jsp-file>home.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>home</servlet-name>
<url-pattern>/home</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>login</servlet-name>
<jsp-file>login.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>logincredentials</servlet-name>
<jsp-file>logincredentials.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>logincredentials</servlet-name>
<url-pattern>/logincredentials</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>completequiz</servlet-name>
<jsp-file>completequiz.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>completequiz</servlet-name>
<url-pattern>/completequiz</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>instructions</servlet-name>
<jsp-file>instructions.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>instructions</servlet-name>
<url-pattern>/instructions</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>workInstruction</servlet-name>
<jsp-file>workInstruction.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>workInstruction</servlet-name>
<url-pattern>/workInstruction</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
<!-- <welcome-file>/home</welcome-file> <welcome-file>/logincredentials</welcome-file>
<welcome-file>/quiz</welcome-file> <welcome-file>/quizInstructions</welcome-file>
<welcome-file>/completequiz</welcome-file> -->
</welcome-file-list>
</web-app>
</element>
------------------------------------------------------------------------------
This is my spring-servlet.xml
------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan
base-package="pt.gov.mtss.gep.IEVweb_v2" />
<context:annotation-config />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="cache" value="false" />
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<!-- <property name="templateMode" value="HTML5"/> -->
<property name="order" value="0" />
</bean>
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<mvc:resources mapping="/resources/**"
location="/resources/" cache-period="31556926" />
</beans>
Каждый раз, когда я получаю это сообщение:
2019-09-20 09: 34: 14.298 INFO 12124 --- [on (1) -127.0.0.1] oaccC [Tomcat]. [localhost]. [/]: инициализация Spring DispatcherServlet 'dispatcherServlet' 2019-09-20 09: 34: 14.299 INFO 12124 --- [on (1) -127.0.0.1] osweb.servlet.DispatcherServlet: инициализация сервлета 'dispatcherServlet' 2019-09-20 09: 34: 14.307 INFO 12124 --- [on (1) -127.0.0.1] osweb.servlet.DispatcherServlet: Завершение инициализации за 8 мс 2019-09-20 09: 35: 03.053 WARN 12124 ---[nio-8080-exec-5] osweb.servlet.PageNotFound: Нет отображения для GET /home.html