1. 程式人生 > >java-新建簡單的Web項目

java-新建簡單的Web項目

b- 初始化 mapping lis 請求 spa encoding har 默認

參考鏈接:

https://www.cnblogs.com/silentdoer/articles/7134332.html

技術分享圖片

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1"> <display-name>fileConvert</display-name> <!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml,classpath:spring-mybatis.xml,classpath:spring-shiro.xml</param-value> </context-param>
--> <!-- 配置DispatchcerServlet --> <!-- springmvc 前端控制器 --> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <
param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <!-- load-on-startup:表示啟動容器時初始化該Servlet; --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <!-- url-pattern:表示哪些請求交給Spring Web MVC處理, “/” 是用來定義默認servlet映射的。 --> <!-- 也可以如“*.html”表示攔截所有以html為擴展名的請求。 --> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 指定歡迎頁面 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>

springmvc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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">
                                      <!-- 註意上面的也可以寫成spring-context-4.3.xsd,如果不寫則默認是用當前的版本 -->
                                      
    <!-- 配置Controller掃描  -->
    <context:component-scan base-package="lee.files.controller"></context:component-scan>
    
    <!-- 配置視圖解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 前綴 -->
        <property name="prefix" value="/WEB-INF/pages/views/" />
        <!-- 後綴 -->
        <property name="suffix" value=".jsp" />
    </bean>
                                     
</beans>

index.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
response.sendRedirect("file/fileConvert");
%>

技術分享圖片

Tomcat啟動報錯:

Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]

可能是引入jar包不全導致

java-新建簡單的Web項目