zoukankan      html  css  js  c++  java
  • 05 图书管理系统(SSM+LayUi)

    整合SpringMVC

    1、在web.xml中配置前端控制器和中文乱码处理

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
             
        <display-name>Archetype Created Web Application</display-name>
    
        <!-- 配置中文乱码处理 -->
        <filter>
            <filter-name>characterEncodingFilter</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>characterEncodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <!-- 配置前端控制器 -->
        <servlet>
            <servlet-name>dispatcherServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <!-- 加载springmvc的配置文件 -->
            <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>dispatcherServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
    
    
    </web-app>
    
    

    2、在resources中新建springmvc.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.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <!-- 开启注解扫描 只扫描controller层 -->
        <context:component-scan base-package="com.gychen.controller">
    
        </context:component-scan>
    
        <!-- 配置视图解析器 -->
        <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- 前缀 -->
            <property name="prefix" value="/WEB-INF/pages/"/>
            <!-- 后缀 -->
            <property name="suffix" value=".jsp"/>
        </bean>
    
    
        <!-- 过滤静态资源 -->
    
    
        <!-- 开启springmvc的注解支持 -->
        <mvc:annotation-driven/>
    
    </beans>
    

    3、测试springmvc

    • 在com.gychen.controller中新建TestController
    package com.gychen.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class TestController {
        @RequestMapping("/test")
        public String testIndex(){
            System.out.println("测试springmvc内容");
            return "test";
        }
    }
    
    
    • 在WEB-INF里新建pages/test.jsp
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>SpringMVC测试</title>
    </head>
    <body>
        SpringMVC测试
    </body>
    </html>
    

    4、配置Tomcat并把项目添加到Tomcat服务器中

  • 相关阅读:
    nohup: failed to run command `java': No such file or directory
    HDU4845(SummerTrainingDay02-C 状态压缩bfs)
    Codeforces731C(SummerTrainingDay06-M 并查集)
    Codeforces485D(SummerTrainingDay01-K)
    POJ2227(优先队列)
    Codeforces833A
    HDU3534(SummerTrainingDay13-C tree dp)
    Codeforces687C(SummerTrainingDay03-D DP)
    POJ1811(SummerTrainingDay04-G miller-rabin判断素性 && pollard-rho分解质因数)
    HDU6113
  • 原文地址:https://www.cnblogs.com/nuister/p/13361182.html
Copyright © 2011-2022 走看看