Tôi đang cố gắng sử dụng thẻ <mvc:resources>
Spring MVC: thẻ nguồn lực và 404 lỗi
đây là cấu trúc dự án của tôi
những gì tôi muốn là tiếp cận với javascript trong thư mục js và css trong thư mục phong cách
Tuy nhiên, bất cứ khi nào tôi thêm này để tôi điều phối-servlet.xml
<mvc:resources mapping="/resources/**" location="/"/>
tôi bị lỗi 404, khi chạy dự án (dự án sẽ chuyển hướng đến login.htm đó là trang login.jsp)
này là mã dispatcher-servlet.xml tôi
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.swcommodities.wsmill.controller"/>
<mvc:resources mapping="/resources/**" location="/"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/"
p:suffix=".jsp" />
<tx:annotation-driven/>
.
.
.
</beans>
đây là web .xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
tôi không biết tại sao tôi xoá dòng <mvc:resources...
dự án chạy một cách chính xác, nhưng khi thêm một này đối với dự án, tôi nhận được lỗi 404 ngay lập tức. Tôi nghĩ rằng điều này làm cho một số xung đột với dự án hiện tại.
Bạn phải chính xác cho câu trả lời hợp lệ. Bạn đã viết "Tôi gặp lỗi 404, khi chạy dự án" - Bạn đang yêu cầu URL nào ?! và bạn mong chờ tệp nào (vị trí)? – Ralph
bạn đã nhấn vào url nào trong trình duyệt và chúng tôi sẽ cần tệp cấu hình bean của bạn –
xin lỗi vì điều đó, khi chạy dự án, nó sẽ chuyển hướng đến login.htm có nghĩa là trang login.jsp. –