zoukankan      html  css  js  c++  java
  • SpringMvc入门二----HelloWorld

    1. 导入需要的架包:

    2. 配置web.xml,添加Servlet

        <servlet>

            <servlet-name>springmvc</servlet-name>

            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

            <init-param>

                <param-name>contextConfigLocation</param-name>

                <param-value>classpath:spring-mvc.xml</param-value>

            </init-param>

        </servlet>

        <servlet-mapping>

            <servlet-name>springmvc</servlet-name>

            <url-pattern>*.do</url-pattern>

        </servlet-mapping>

    3. 添加spring-mvc.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:p="http://www.springframework.org/schema/p"

         xmlns:context="http://www.springframework.org/schema/context"

         xsi:schemaLocation="

         http://www.springframework.org/schema/beans

         http://www.springframework.org/schema/beans/spring-beans.xsd

         http://www.springframework.org/schema/context

         http://www.springframework.org/schema/context/spring-context.xsd">

        <!-- 使用注解的包,包括子集 -->

         <context:component-scan base-package="com.java1234"/>

    <!-- 视图解析器 -->

            <bean id="viewResolver"

            class="org.springframework.web.servlet.view.InternalResourceViewResolver">

            <property name="prefix" value="/WEB-INF/jsp/" />

            <property name="suffix" value=".jsp"></property>

            </bean>

    </beans>

    4. 在index.jsp中添加如下代码:

        <body>

    <a href="helloWorld.do">Hello World SpringMvc</a>

    </body>

    5. 在/WEB-INF/下新建一个jsp文件,在jsp文件夹下建立一个helloword.jsp文件

        <%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>Insert title here</title>

    </head>

    <body>

    ${message }

    </body>

    </html>

    6. 编写Controller类HelloWorldController.java:

        @Controller

    public class HelloWorldController {

            @RequestMapping("/helloWorld")

            public String helloWorld(Model model){

                model.addAttribute("message", "StringMvc大爷你好!");

                return "helloWorld";

            }

    }

    7. 整个项目图:

        

    8. 测试:http://localhost:8080/SpringMvc01/

  • 相关阅读:
    哈希和不可哈希
    TCP/IP 学习笔记1 浅谈TCP和UDP
    让我们来开发一种更类似人脑的神经网络吧(三)
    关于用CUDA优化三层反传神经网络算法
    让我们来开发一种更类似人脑的神经网络吧(二)
    让我们来开发一种更类似人脑的神经网络吧(六)
    Matlab笔记
    记忆的模式
    让我们来开发一种更类似人脑的神经网络吧(五)
    总结一下感受器官和大脑的通信原理
  • 原文地址:https://www.cnblogs.com/bb1119/p/5554957.html
Copyright © 2011-2022 走看看