码迷,mamicode.com
首页 > 编程语言 > 详细

1.SpringMVC部署

时间:2017-05-11 00:20:44      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:ice   name   访问   ges   ima   logs   nbsp   3.0   return   

1.在MyEclipse中部署:(项目结构图)

技术分享技术分享

 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"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
    <!-- Spring MVC配置 -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

spring-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/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <!-- 启动注解驱动的Spring MVC功能,注册请求url和注解POJO类方法的映射-->  
    <mvc:annotation-driven >
         
    </mvc:annotation-driven>
   
    <!-- 启动包扫描功能,以便注册带有@Controller、@service、@repository、@Component等注解的类成为spring的bean -->
    <context:component-scan base-package="com.springmvc" />
    <!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
         <property name="prefix" value="/"/>    <!-- 前缀 -->
         <property name="suffix" value=".jsp"/>    <!-- 后缀 -->
     </bean>
</beans>

controller文件:

 1 package com.springmvc;
 2 
 3 
 4 import org.springframework.stereotype.Controller;
 5 import org.springframework.web.bind.annotation.RequestMapping;
 6 
 7 @Controller
 8 @RequestMapping("/Test/*") 
 9 public class HelloWorld
10 {
11      //访问地址:http://localhost:8080/Test/returnSuccess
12     @RequestMapping(value = "returnSuccess")    //实际访问的url地址
13     public String returnSuccess() {
14         return "success";    //返回Views文件夹下的success.jsp页面
15     }
16 }

 在MyEclipse中,存储源代码的叫工作空间(workplace),在里面可以建不同的项目。针对JavaWeb项目,浏览器访问时需要添加对应的项目,如下图中的springmvc。技术分享

 

1.SpringMVC部署

标签:ice   name   访问   ges   ima   logs   nbsp   3.0   return   

原文地址:http://www.cnblogs.com/nevegiveup/p/6838780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!