Это мой пакет:
package com.demo.controllers;
import java.util.Random;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MyDemoController {
private String[] quotes = {"To be or not to be -Shakespeare", "Spring is the nature's way of
saying 'let's party'-from someone","The time is always right to do what is right"};
@RequestMapping(value="/getQuote")
public String getRandomQuote(Model model) {
int rand = new Random().nextInt(quotes.length); String randomQuote =quotes[rand];
model.addAttribute("randomQuote", randomQuote);
return "quote"; }
@RequestMapping(value="/createAccount")
public String createAccount() {
return "createAccount";
}
}
Это мой веб. xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My Demo App</display-name>
<servlet>
<servlet-name>MyDemoApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/myDemoApp-servletConfig.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyDemoApp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
****** servlet.config *****
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 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-4.3.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.demo.controllers"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property> </bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <bean name="/getQuote.html" class="com.demo.controllers.MyDemoController" /> <bean name="/createAccount.html" class="com.demo.controllers.MyDemoController" />
</beans>
Моя цитата. jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content= "text/html; charset=ISO-8859-1">
<title>My Random Quote page</title>
</head>
<body>
<h1>The Quote is:</h1>
<p>${randomQuote}</p>
</body>
</html>
my createAccount. jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Create an Account</title>
</head>
<body>
<h1>Enter Account Details</h1>
<h2>Enter your details</h2>
<form>
<table>
<tr><td>First Name:<input type="text" name= "firstname" /></td></tr>
<tr><td>Last Name:<input type="text" name= "lastname" /></td></tr>
<tr><td>Address:<input type="text" name= "address" /></td></tr>
<tr><td>Email:<input type="text" name= "email" /></td></tr>
<tr><td><input type="submit" value= "Create " /></td></tr>
</table>
</form>
</body>
</html>
- Я получаю веб-страницу для localhost: 8080 / springMVCDemo / getQuote. html
Но я не получаю страницу localhost: 8080 / springMVCDemo / createAccount. html
любые лиды помогут