Hello word

来源:互联网 发布:如何开通淘宝达摩盘 编辑:程序博客网 时间:2024/06/05 07:19

首先加入jar 包:


web.xml中加入:

<servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 有默认的springmvc.xml 目录为WEB-INF/<servlet-name>-servlet.xml--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>

applicationContext.xml加入:

<!--             注解扫描器 --><context:component-scan base-package="com.gjs.springmvc"></context:component-scan><!-- 配置视图解析器  --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/view/"></property><property name="suffix" value=".jsp"></property></bean>

handler类中加入:

@Controllerpublic class HelloWord {@RequestMapping("/helloWork")public String helloWord(){System.out.println("helloWord");return "success";}}


*****************************************************************************************

以上完成简单的hello word!

1 0