springmvc之helloworld
来源:互联网 发布:淘宝优站九块九包邮 编辑:程序博客网 时间:2024/06/05 00:34
springmvc之helloworlddemo小记:
首先在web.xml配置springmvc的前端控制器
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
之后配置springmvc的配置文件,文件名需于web.xml中的配置名相同,如我上方未配置则我的文件名为springmvc-servlet.xml,与上方的servlet-name相同
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--自动扫描的包路径-->
<context:component-scan base-package="com.dadao.controller"></context:component-scan>
<!--静态文件配置-->
<mvc:resources mapping="/html/**" location="/html/" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/image/**" location="/image/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/fonts/**" location="/fonts/" />
<!--启用注解配置-->
<mvc:annotation-driven />
<!--配置视图过滤-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value></value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
首先,springmvc需要加spring-web以及spring-webmvc两个jar包,启动项目。
报java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextAware
加入spring-context jar包
报java.lang.ClassNotFoundException: org.springframework.beans.factory.Aware
加入spring-beans jar包
报java.lang.ClassNotFoundException: org.springframework.core.env.EnvironmentCapable
加入spring-core jar包
报java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WebDemo]]
加入commons-logging jar包
报org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/springmvc-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
加入spring-aop jar包
报java.lang.NoClassDefFoundError: org/springframework/expression/ParserContext
加入spring-expression jar包
项目运行成功
添加javawenjian
@Controller
public class HelloController {
@RequestMapping(value="/hello")
public String hello(Model model){
model.addAttribute("msg","你好,spingmvc");
return "index";
}
}
浏览器输入地址/hello
出现你好,springmvc
至此,ok
- 【springmvc】 springmvc 之 HelloWorld
- springmvc之HelloWorld
- 剖析springmvc之HelloWorld
- springmvc之helloworld
- SpringMVC之HelloWorld
- SpringMVC实例之HelloWorld
- SpringMVC之“HelloWorld”起步
- springmvc之helloworld
- SpringMVC之HelloWorld。
- SpringMVC框架之HelloWorld
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- 学习SpringMVC(一)之helloworld
- springMVC web工程之 HelloWorld
- SpringMVC开发之HelloWorld案例以及分析
- c++中为什么父类名可以直接调用自己的非静态函数测试例子!(父类名::非静态函数)
- 动态规划 最长公共子序列 过程图解
- 位移运算符和位运算符的计算
- QT之Layout
- unity中UGUI图片箭头指向鼠标位置
- springmvc之helloworld
- NYOJ 239 月老的难题(最大二分图匹配)
- 论企业信息化之六:业务架构
- Bootstrap组件学习笔记(五)——标签、徽章和巨幕
- c++ stl 分析
- 图像算法
- RxJS常用操作符
- 最大公约数与最小公倍数
- 我的座右铭