如何链接到其他页面? [英] How do I link to another page?
问题描述
我的代码是这样的。我认为问题可能出现在我的web.xml文件中。你能帮助我吗?
这是我在webContent下的index.html
< !DOCTYPE html >
< html >
< head >
< meta charset = ISO-8859-1 >
< title > 存储< / title >
< / head >
< body >
< a href = / store / addProduct.html > 添加产品< / a >
< / body >
< / html >
这是我在WebContent / Web-INF /下的addProduct.html html:
< !DOCTYPE html >
< span class =code-keyword>< html xmlns = http://www.w3.org/1999/xhtml
xmlns:th = http:// www.thymeleaf.org >
< 头温泉n> >
< meta charset = ISO-8859-1 >
< title > 添加商品< / title >
< / head >
< 正文 >
<! - < form action =#th:action =@ {/ newProduct} method =交的> - >
<! - < span class =code-keyword> < button type =submit>提交< / button> - >
<! - < span class =code-keyword> < / form> - >
< / body >
< / html >
这是我在webContent / WEB-INF下的web.xml
<? xml version = 1.0 encoding = UTF-8 ? >
< web-一个pp xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance xmlns = http://java.sun.com/xml/ns / javaee 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 > CrunchifySpringMVCTutorial < / display-name >
< span class =code-keyword>< welcome-file-list >
< welcome-file > index.html< / welcome-file >
< / welcome-file-list >
< servlet >
< servlet-name > 存储< < span class =code-leadattribute> / servlet-name >
< servlet-class >
org.springframework.web.servlet.DispatcherServlet
< / servlet-class >
< load-on-startup > 1 < / load-on-startup >
< / servlet >
< servlet-mapping >
< servlet-name > store < / servlet-name >
< url-pattern > ; /addProduct.html < / url-pattern >
<! - < url-pattern> /index.jsp< / url-pattern> - >
<! - < span class =code-keyword> < url-pattern> /welcome.html< / url-pattern> - >
<! - < span class =code-keyword> < url-pattern> * .html< / url-pattern> - >
< / servlet-mapping >
< / web-app >
这是我在WebContent / WEB-INF下的store-servlet.xml
< beans xmlns = http://www.springframework.org/schema/beans
xmlns:mvc = http://www.springframework.org/schema/ MVC跨度> < span class =code-attribute> 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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org /schema/mvc/spring-mvc.xsd
http:// www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd\">
< context:component-scan base-package = com.ecommerce.store / >
< bean id = viewResolver
类 = org.springframework.web.servlet.view.UrlBasedViewResolver >
< property name = viewClass
值 = org.springframework.web.servlet.view.JstlView / >
< property 名称 = 前缀 value = / WEB-INF / html / / >
< property 名称 = < span class =code-keyword>后缀 value = .html / >
< / bean >
< < span class =code-leadattribute> / beans >
无论我尝试什么,我都会遇到同样的错误:
9月。 12 , 2017 3 : 11 : 50 PM org.springframework.web.servlet.PageNotFound noHandlerFound
AVERTISSEMENT:未找到映射 for 在DispatcherServlet中使用URI [/store/addProduct.html]的HTTP请求,其名称为' store'
你能帮我吗?我很绝望。
我尝试了什么:
我我曾尝试在很多方面改变我的web.xml但我无法正确使用它。
错误很明显,你提供的导航页面未建立尝试完整您的链接的路径或尝试
< a href = @您的页面路径/ file.html>链接< / a>
My code is this. I think the problem might be something in my web.xml file. Can you help me?
This is my index.html under WebContent
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Store</title>
</head>
<body>
<a href="/store/addProduct.html">Add a product</a>
</body>
</html>
This is my addProduct.html under WebContent/Web-INF/html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Add a product</title>
</head>
<body>
<!-- <form action="#" th:action="@{/newProduct}" method="post"> -->
<!-- <button type="submit">Submit</button> -->
<!-- </form> -->
</body>
</html>
This is my web.xml under WebContent/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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>CrunchifySpringMVCTutorial</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>store</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>store</servlet-name>
<url-pattern>/addProduct.html</url-pattern>
<!-- <url-pattern>/index.jsp</url-pattern> -->
<!-- <url-pattern>/welcome.html</url-pattern> -->
<!-- <url-pattern>*.html</url-pattern> -->
</servlet-mapping>
</web-app>
This is my store-servlet.xml under WebContent/WEB-INF
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.ecommerce.store" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/html/" />
<property name="suffix" value=".html" />
</bean>
</beans>
And no matter what I try I keep getting the same error:
sept. 12, 2017 3:11:50 PM org.springframework.web.servlet.PageNotFound noHandlerFound
AVERTISSEMENT: No mapping found for HTTP request with URI [/store/addProduct.html] in DispatcherServlet with name 'store'
Can you help me please? I'm desperating.
What I have tried:
I've tried changing my web.xml in many ways but I cant get it right.
Error is much clear that your provided page to navigate is not founded try full path to your link or try
<a href=@"your page path/file.html">Link</a>
这篇关于如何链接到其他页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!