gpt4 book ai didi

java - org.springframework.web.servlet.DispatcherServlet noHandlerFound警告: No mapping for GET/springMVCDemo/createAccount. html

转载 作者:行者123 更新时间:2023-12-01 16:13:51 24 4
gpt4 key购买 nike

这是我的包裹:


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";
}
}

这是我的 web.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>

我的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>

  1. 我获取了 localhost:8080/springMVCDemo/getQuote.html 的网页
  2. 但是我没有看到以下页面本地主机:8080/springMVCDemo/createAccount.html

  3. 任何线索都会有所帮助

最佳答案

错误背后的原因是 Tomcat,我们需要构建并重新发布才能正确加载所有页面

关于java - org.springframework.web.servlet.DispatcherServlet noHandlerFound警告: No mapping for GET/springMVCDemo/createAccount. html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62453955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com