侧边栏壁纸
  • 累计撰写 793 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录

xml 示例

Dettan
2021-04-10 / 0 评论 / 0 点赞 / 158 阅读 / 1,201 字
温馨提示:
本文最后更新于 2022-07-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

web.xml
web.xml servlet没有覆盖的直接就当成资源文件处理了

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <servlet>
        <description>spring mvc servlet</description>
        <servlet-name>springMvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <description>spring mvc 配置文件</description>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:conf/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springMvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
		 <servlet-mapping>
        <servlet-name>springMvc</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>springMvc</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <!--<welcome-file>index.jsp</welcome-file>-->
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>

    <error-page>
        <error-code>404</error-code>
        <location>/common/building.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/common/error.jsp</location>
    </error-page>

    <servlet>
        <servlet-name>toHtml</servlet-name>
        <servlet-class>com.key.common.utils.ToHtmlServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>toHtml</servlet-name>
        <url-pattern>/toHtml</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>com.key.common.utils.web.InitAppliction</listener-class>
    </listener>
</web-app>

spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:mvc="http://www.springframework.org/schema/mvc" 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-3.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://www.springframework.org/schema/mvc
		 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
		 http://cxf.apache.org/jaxws
		 http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx.xsd
   		 http://cxf.apache.org/schemas/jaxws.xsd
   		 http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    <!--    <mvc:default-servlet-handler/>-->
    <aop:aspectj-autoproxy/>
    <mvc:annotation-driven/>
    <context:component-scan base-package="com.key.common.base.action,com.key.dwsurvey.controller"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/WEB-INF/wjHtml/**" location="/WEB-INF/wjHtml/"/>

    <!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->
    <bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:order="3">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="contentType" value="text/html"/>
        <property name="prefix" value="/WEB-INF/page/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
    <!-- 加载controller的时候,不加载service,因为此时事物并未生效,若此时加载了service,那么事物无法对service进行拦截 -->
    <!--	<context:component-scan base-package="org.jeecgframework.web.*,com.jeecg.*,com.yby.*">-->
    <!--		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />-->
    <!--	</context:component-scan>-->

    <!-- ResponseBody返回字符串带双引号解决 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--        <property name="prefix">-->
        <!--            <value>/WEB-INF/views/</value>-->
        <!--        </property>-->
        <property name="suffix" value=".jsp"/>
    </bean>
    <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
        <constructor-arg value="UTF-8" index="0"/>
        <property name="supportedMediaTypes">
            <list>
                <value>text/plain;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 注册handler method和request的mapping关系。 -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>


    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
          p:defaultEncoding="UTF-8">
        <property name="maxUploadSize" value="104857600"/>
        <property name="maxInMemorySize" value="4096"/>
    </bean>

    <!-- Bean解析器,级别高于默认解析器,寻找bean对象进行二次处理 -->
    <bean id="beanNameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>
    <!-- 拦截器 -->
    <!--	<mvc:interceptors>-->
    <!--		<mvc:interceptor>-->
    <!--			<mvc:mapping path="/**" />-->
    <!--			<bean class="org.jeecgframework.core.interceptors.EncodingInterceptor" />-->
    <!--		</mvc:interceptor>-->
    <!--	</mvc:interceptors>-->
</beans>
0

评论区