Spring MVC helloWorld中遇到的问题及解决办法
1、java.io.FileNotFoundException: Could not open ServletContext resource
不能加载ServletContext的用法是配置到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_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVCLesson</display-name> <servlet>
<servlet-name>SpringMVCLesson</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springservlet-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup><!-- load-on-startup必须放在最后 -->
</servlet>
<!-- Spring MVC配置文件结束 --> <servlet-mapping>
<servlet-name>SpringMVCLesson</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> </web-app>
解决办法:
更改xml名字为 {ServletContext}-servlet.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!--<start id="servlet_DispatcherServlet"/>-->
<servlet>
<servlet-name>SpringMVCLesson</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--<end id="servlet_DispatcherServlet"/>--> <servlet-mapping>
<servlet-name>SpringMVCLesson</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> </web-app>
位置仍为/WEB-INF/下
2、org.springframework.web.servlet.DispatcherServlet noHandlerFound
解决办法:
SpringMVCLesson-servlet.xml增加
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
这个工程中还有个特殊问题是Source Folder设置错误导致java没有生成class文件
3、其它xml:xsi没有配置正确导致配置的元素没有被识别而报错
<?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:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--<start id="spring_component_scan" />-->
<context:component-scan base-package="com.demo.web.controllers" />
<!--<end id="spring_component_scan" />--> <!--<start id="mvc_annotatedcontrollers" />-->
<mvc:annotation-driven/>
<!--<end id="mvc_annotatedcontrollers" />--> <!--<start id="mvc_resources"/>-->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!--<end id="mvc_resources"/>--> </beans>
4、Spring中CoC(Convention over Configration)约定优于配置的理解又加深了
Spring MVC helloWorld中遇到的问题及解决办法的更多相关文章
- Spring MVC @Transactional注解方式事务失效的解决办法
在springMVC类上绑定@Transactional的注解,但是访问数据库时,总是报 can't localtion to current JTA Transactional. 后来发现sprin ...
- Spring MVC Controller中解析GET方式的中文参数会乱码的问题(tomcat如何解码)
Spring MVC Controller中解析GET方式的中文参数会乱码的问题 问题描述 在工作上使用突然出现从get获取中文参数乱码(新装机器,tomcat重新下载和配置),查了半天终于找到解决办 ...
- Spring MVC程序中得到静态资源文件css,js,图片文件的路径问题总结
上一篇 | 下一篇 Spring MVC程序中得到静态资源文件css,js,图片 文件的路径 问题总结 作者:轻舞肥羊 日期:2012-11-26 http://www.blogjava.net/fi ...
- spring mvc controller中获取request head内容
spring mvc controller中获取request head内容: @RequestMapping("/{mlid}/{ptn}/{name}") public Str ...
- iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】
在osx 10.11之前cocopods问题不多,但是升级到11之后的版本,之前的cocopods大多用不了,需要重新安装,对于我这种使用测试版系统的技术狂来说,每次都需要重新安装很多东西, 当然,c ...
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
发布mvc遇到的HTTP错误 403.14-Forbidden解决办法 <system.webServer> <validationvalidateIntegratedMod ...
- MyEclipse代码编辑器中汉字太小的解决办法(中文看不清)
问题描述:新安装的myeclipse 2014,代码编辑器中汉字很小看不清 解决办法:调整字体即可.通过菜单Windows——Preferences,输入font过滤选择Colors and Font ...
- 虚拟机中不能连接usb设备解决办法
虚拟机中不能连接usb设备解决办法 1.点击开始->运行,在对话框中输入"services.msc",确定,打开windows服务管理器.2.在服务列表中选中"VM ...
- Aasible中cryptography兼容性报错解决办法
Aasible中cryptography兼容性报错解决办法 1 Ansible中使用ansible --version查看版本,报错信息如下: ERROR! Unexpected Exception, ...
随机推荐
- 使用Jmeter至WebService压力测试
使用Jmeter至WebService压力测试 目中我们使用了Jmeter对webservice进行了压力測试,Apache JMeter是Apache组织开发的基于Java的压力測试工具.用于对 ...
- kiss框架学习
#parse("$!jc.skinpath/exam/cart.ascx") var CategoryId = "$!this.loadCategory_combo(). ...
- git flow 的使用
在这里主要讲一下我在项目中用到的关于gitflow的使用方法. 公司的项目中,专门有一台用来存放版本号库的server,路径是在默认的安装文件夹/opt/git/,那么在使用的时候,假设你是 ...
- Struts2他们拦截器实例定义—登陆权限验证
版本号:struts2.1.6 这种情况下实现功能:用户需要指定username登陆,进入相应的页面运行成功登陆作战,否则,它返回到着陆的登录页面,当直接进入操作页面(登陆访问页面后的能力)如果不同意 ...
- 16位图像Alpha混合的实现(用汇编写的,比MMX还要快)
Alpha 混合的算法很简单,基于下面的公式就可以实现: D := A * (S - D) / 255 + D D 是目标图像的像素, S 是源图像的像素 A 是 Alpha 值, 0 为全透明, 2 ...
- HUST 1569(Burnside定理+容斥+数位dp+矩阵快速幂)
传送门:Gift 题意:由n(n<=1e9)个珍珠构成的项链,珍珠包含幸运数字(有且仅由4或7组成),取区间[L,R]内的数字,相邻的数字不能相同,且旋转得到的相同的数列为一种,为最终能构成多少 ...
- POJ 3076 Sudoku (dancing links)
题目大意: 16*16的数独. 思路分析: 多说无益. 想说的就是dancing links 的行是依照 第一行第一列填 1 第一行第二列填 2 -- 第一行第十五列填15 第一行第二列填 1 -- ...
- M I S 开发与管理
今天是开学的第一天,很意外的一天没课.但是我知道还有很多事情在等待这我,不能懈怠!安排好计划,把重要不紧急的事情逐渐蚕食掉,切不可养虎为患,等拖到它变成重要紧急事件后,那就后悔莫及了. 下午看了看自考 ...
- UVa 10188 - Automated Judge Script
题目:给你一些题目的输出结果,推断是AC,PE还是WA. 分析:模拟. 依照题意模拟就可以,注意PE条件为全部数字字符出现顺序同样就可以. 说明:想起非常多年前写的OJ的后台判题程序了╮(╯▽╰)╭. ...
- java nio-理解同步、异步,阻塞和非阻塞
理解同步.异步,阻塞和非阻塞 结论:阻塞.非阻塞与是否同步异步无关. 转自知乎 “阻塞”与"非阻塞"与"同步"与“异步"不能简单的从字面理解, ...