Rumah > Soal Jawab > teks badan
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">
<nama-paparan>Aplikasi Web Dicipta Arketiip</nama-paparan>
<!-- Spring和mybatis的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mybatis.xml</param-value>
</context-param>
<!-- 编码过滤器 -->
<penapis>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</penapis>
<pemetaan penapis>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</pemetaan-penapis>
<!-- Spring监听器 -->
<pendengar>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</pendengar>
<!-- 防止Spring内存溢出监听器 -->
<pendengar>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</pendengar>
<!-- Servis MVC musim bunga -->
<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>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<tapis>
<filter-name>RespFilter</filter-name>
<filter-class>me.lihs.java.utils.ResponseFilter</filter-class>
</filter>
<pemetaan penapis>
<filter-name>RespFilter</filter-name>
<url-pattern>/*</url-pattern>
</pemetaan-penapis>
<senarai-fail-selamat datang>
<welcome-file>/index.jsp</welcome-file>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
</web-app>
spring-mybatis.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"
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-4.0.xsd">
<!-- 自动扫描 -->
<context:component-scan base-package="me.lihs.java"/>
<!-- 引入配置文件 --> bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</kacang><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${dbUrl}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}"/>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${maxActive}"/>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${maxIdle}"/>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}"/>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}"/>
</kacang><!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="ringsion.mySqbatisl;
<property name="dataSource" ref="dataSource"/>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:me/lihs/java/mapping/*.xml"/>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.ScannerConfigurer">Configurer
<property name="basePackage" value="me.lihs.java.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</kacang>
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: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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!--Halang IE daripada mengembalikan JSON dan memuat turun fail apabila melaksanakan AJAX -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</kacang>
<!-- Mulakan fungsi anotasi SpringMVC dan lengkapkan pemetaan permintaan dan anotasi POJO -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter"/> <!-- JSON转换器 -->
</list>
</property>
</bean>
<!-- Tentukan awalan dan akhiran fail lompat, lihat konfigurasi mod-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</kacang>
<!-- Muat naik fail konfigurasi, jika anda tidak menggunakan muat naik fail, anda tidak perlu mengkonfigurasinya Sudah tentu, jika ia tidak dikonfigurasikan, maka tidak perlu memperkenalkan pakej komponen muat naik dalam fail konfigurasi -->
<!--<bean id="multipartResolver "-->
<!--class="org.springframework.web.multipart.commons.CommonsMultipartResolver">-->
<!--<!– 默认编码 –>-->
<!--<property name="defaultEncoding" value="utf-8"/>-->
<!--<!– 文件大小最大值 –>-->
<!--<property name="maxUploadSize" value="500000000"/>-->
<!--<!– 内存中的最大值 –>-->
<!--<property name="maxInMemorySize" value="40960"/>-->
<!--</bean>-->
<mvc:default-servlet-handler/>
</beans>
![Memuat naik gambar...]
世界只因有你2017-05-27 17:42:22
Jika 404 dilaporkan, terdapat masalah dengan halaman, web.xml, fail konfigurasi spring mvc dan Pengawal
1. / ditukar kepada /*
2 Lihat kod Pengawal dan semak sama ada paparan yang dikembalikan adalah betul dan sama ada ia boleh sepadan dengan halaman jsp
.伊谢尔伦2017-05-27 17:42:22
<url-pattern>/</url-pattern> akan memadankan URL jenis laluan seperti /login, tetapi tidak akan sepadan dengan URL jenis akhiran seperti *.jsp
<url-pattern>/</url-pattern> akan sepadan dengan semua URL: URL jenis laluan dan jenis akhiran (termasuk /login, .jsp, #🎜🎜 #.js dan .html, dsb.)
<servlet-name>SpringMVC</servlet-name><url-pattern>/</url-pattern>