SSM框架搭建(终章):配置运行webapp文件

文章目录

    • 一、修改配置
    • 二、页面展示

一、修改配置

在“web”目录下,已经自动创建“WEB-INF”文件夹,并且在“WEB-INF”文件夹中,已经存在“web.xml”文件,我们现在要对这个文件进行修改。


<web-app
    version="4.0"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xml="http://www.w3.org/XML/1998/namespace"
    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">
  <display-name>Archetype Created Web Applicationdisplay-name>
web-app>

可以参考笔者的配置


<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">

    <absolute-ordering/>
    <display-name>Archetype Created Web Applicationdisplay-name>

    
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:applicationContext.xmlparam-value>
    context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener>

    
    <filter>
        <filter-name>CharacterEncodingFilterfilter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
        <init-param>
            <param-name>Encodingparam-name>
            <param-value>UTF-8param-value>
        init-param>
    filter>

    <filter-mapping>
        <filter-name>CharacterEncodingFilterfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>


    <servlet>
        <servlet-name>dispatchServletservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        
        <init-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:applicationContext-mvc.xmlparam-value>
        init-param>
        <load-on-startup>1load-on-startup>
    servlet>
    <servlet-mapping>
        <servlet-name>dispatchServletservlet-name>
        
        <url-pattern>/url-pattern>
    servlet-mapping>


web-app>

在“web”目录下,创建或修改“index.jsp”文件,作为项目的默认页面。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<body>
<h2><%= "Hello World!" %>h2>
<a href="http://localhost:8080/SSM_Demo_war/register.jsp">注册a>
<a href="http://localhost:8080/SSM_Demo_war/delete.jsp">删除a>
<a href="http://localhost:8080/SSM_Demo_war/modify.jsp">修改a>
<a href="http://localhost:8080/SSM_Demo_war/selectOne.jsp">查询单用户a>
<a href="http://localhost:8080/SSM_Demo_war/selectAllUser.do">查询全部用户a>
body>
html>

二、页面展示

SSM框架搭建(终章):配置运行webapp文件_第1张图片

你可能感兴趣的:(SSM框架,Java,服务器,web,app,java,maven,tomcat)