我知道这个问题已经多次了,我尝试了很多次,但它不起作用。我有一些错误,我不知道如何处理它们。服务器看起来像是无法识别csp文件和jsp文件中定义的javascript文件。
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" id="WebApp_ID"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<display-name>spring-mvc-crud-demo</display-name>
<welcome-file-list>
<welcome-file>Index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-crud-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
servlet.xml中
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" 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
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Add support for component scanning -->
<context:component-scan base-package="com.controller" />
<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WebContent/" />
<property name="suffix" value=".jsp" />
</bean>
控制器
package com.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value= "/intent", method= RequestMethod.POST)
public class IntentController {
@RequestMapping("/notepad")
public String Notepad(){
System.out.println("Notepad is redy");
return "Index";
}
错误 服务器没有看到css文件和javascript。
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/css/noscript.css] in DispatcherServlet with name 'dispatcher'
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/jquery.min.js] in DispatcherServlet with name 'dispatcher'
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/css/mainCss.css] in DispatcherServlet with name 'dispatcher'
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/skel.min.js] in DispatcherServlet with name 'dispatcher'
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/util.js] in DispatcherServlet with name 'dispatcher'
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/main.js] in DispatcherServlet with name 'dispatcher'
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ApiAi/images/pic03.jpg] in DispatcherServlet with name 'dispatcher'
答案 0 :(得分:1)
项目结构将有助于给出确切的答案。 虽然这可能不起作用,因为您没有在servlet.xml文件中提供资源映射。通过使用以下标记提供适当的资源路径映射再次尝试
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(loggs\.no)$ [NC]
RewriteRule ^(.*?)/?$ https://%1/$1/ [L,R=301,NE]
RewriteCond %{THE_REQUEST} \s/+(show|feeds|links)(?:\.php)?\?id=([0-9]+) [NC]
RewriteRule ^ %1/%2/? [R=301,NE,L]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,NE,L]
# add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
RewriteRule ^(show|feeds|links)/([0-9]+)/?$ $1.php?id=$1 [L,QSA,NC]
RewriteRule ^(show|feeds|links)/?$ $1.php [L,NC]