springmvc之helloworld

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





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值