初学springmvc求助, 404 not found

freeman932 2015-03-12 06:19:44
为什么一个最简单的helloworld项目总是404 found错误,但运行目录下的jsp文件可以正常浏览。从网上下的其他人的简单项目也是404 found。难道是机器配置或Jar包的问题。
...全文
373 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
DobyJin 2016-04-19
  • 打赏
  • 举报
回复
使用动态路径应该会稳定些。
qq_28042035 2016-04-18
  • 打赏
  • 举报
回复
楼主我也遇到了同样的问题,你是怎么解决的呀
freeman932 2015-03-13
  • 打赏
  • 举报
回复
初步弄清了原因,是tomcat路径的问题
宁波老花 2015-03-12
  • 打赏
  • 举报
回复
可能是你的HTML文件没放在WebRoot下,而是不小心放到WEB-INF文件夹里了
freeman932 2015-03-12
  • 打赏
  • 举报
回复
hello-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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.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-3.1.xsd"> <context:component-scan base-package="zttc.itat.controller"/> <mvc:annotation-driven/> <!-- 将静态文件指定到某个特殊的文件夹中统一处理 --> <mvc:resources location="/resources/" mapping="/resources/**"/> <bean name="/welcome.html" class="zttc.itat.controller.WelcomeController"></bean> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 设置multipartResolver才能完成文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="5000000"></property> </bean> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="zttc.itat.model.UserException">error</prop> </props> </property> </bean> </beans>
freeman932 2015-03-12
  • 打赏
  • 举报
回复
web.xml <?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <servlet> <servlet-name>hello</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- spring Web MVC框架提供了org.springframework.web.filter.CharacterEncodingFilter用于解决POST方式造成的中文乱码问题 --> <filter> <filter-name>CharacterFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
freeman932 2015-03-12
  • 打赏
  • 举报
回复
比如localhost/springmvc_hello/login.jsp就可以正常显示,而localhost/springmvc_hello/welcome.html就404 not found。清除了tomcat的缓存还是同样的错误。tomcat的servel.xml配置: <Server port="8005" shutdown="SHUTDOWN"> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true" maxPostSize="0"/> <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" useBodyEncodingForURI="true" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="F:\JavaProgram" debug="0" reloadable="false" crossContext="true"> </Context> </Host> </Engine> </Service> </Server>
引用 1 楼 magi1201 的回复:
404 路径问题 看看路径哪里出问题了,再看看是否有缓存的影响等。
姜小白- 2015-03-12
  • 打赏
  • 举报
回复
404 路径问题 看看路径哪里出问题了,再看看是否有缓存的影响等。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧