Java +Tomcat + SpringMVC實(shí)現(xiàn)頁面訪問示例解析
window7下Java環(huán)境安裝記錄:
一、安裝Tomcat
1、下載tomcat 7.0,解壓,無需安裝,放置到目錄:D:\apache-tomcat-7.0.90。
2、配置系統(tǒng)環(huán)境變量,CATALINA_BASE=D:\apache-tomcat-7.0.90,CATALINA_HOME=D:\apache-tomcat-7.0.90,在Path中新增“%CATALINA_HOME%\lib;%CATALINA_HOME%\bin”的環(huán)境變量。
3、進(jìn)入D:\apache-tomcat-7.0.90\bin,執(zhí)行startup啟動(dòng)tomcat,瀏覽器中輸入“127.0.0.1:8080”即可查看是否成功。
二、使用SpringMVC搭建頁面
1、使用Idea創(chuàng)建SpringMVC工程,webAppTest2

2、修改web/WEB-INF/web.xml的url規(guī)則為接受所有
<?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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
3、在src下創(chuàng)建dispatcher-servlet.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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- scan the package and the sub package -->
<context:component-scan base-package="test"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler />
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前綴 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 后綴 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>
4、在src下創(chuàng)建test目錄,目錄下同時(shí)創(chuàng)建MyController文件
package test;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/mvc")
public class MyController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
5、在web/WEB-INF下創(chuàng)建classes和lib文件夾,用來設(shè)置編譯的.class文件目錄和第三方依賴包目錄。

6、web/WEB-INF/下創(chuàng)建jsp目錄,并在目錄下創(chuàng)建hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> Hello world!!!! </body> </html>
7、打war包Build-->Build Artifacts,包名webAppTest2,放到D:\apache-tomcat-7.0.90\webapps目錄下。
8、重啟tomcat,訪問http://127.0.0.1:8080/webAppTest2/mvc/hello 即可。

9、也可以設(shè)置Idea內(nèi)置Tomcat,直接Idea內(nèi)啟動(dòng)瀏覽器


10、省略工程名,直接訪問即可

到此這篇關(guān)于Java +Tomcat + SpringMVC實(shí)現(xiàn)頁面訪問示例解析的文章就介紹到這了,更多相關(guān)Java Tomcat SpringMVC 頁面訪問內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Spring Boot實(shí)現(xiàn)Undertow服務(wù)器同時(shí)支持HTTP2、HTTPS的方法
- 使用 Spring Boot 內(nèi)嵌容器 Undertow創(chuàng)建服務(wù)器的方法
- SpringBoot整合TomCat實(shí)現(xiàn)本地圖片服務(wù)器代碼解析
- Tomcat啟動(dòng)springboot項(xiàng)目war包報(bào)錯(cuò):啟動(dòng)子級(jí)時(shí)出錯(cuò)的問題
- Springboot如何切換默認(rèn)的Tomcat容器
- SpringMVC Tomcat控制臺(tái)亂碼問題解決方案
- Springboot內(nèi)置tomcat配置虛擬路徑過程解析
- springboot 基于Tomcat容器的自啟動(dòng)流程分析
- SpringBoot如何取消內(nèi)置Tomcat啟動(dòng)并改用外接Tomcat
- Spring Boot如何使用Undertow代替Tomcat
相關(guān)文章
Java NumberFormat格式化float類型的bug
今天小編就為大家分享一篇關(guān)于Java NumberFormat格式化float類型的bug,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10
Feign 集成 Hystrix實(shí)現(xiàn)不同的調(diào)用接口不同的設(shè)置方式
這篇文章主要介紹了Feign 集成 Hystrix實(shí)現(xiàn)不同的調(diào)用接口不同的設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
使用postman傳遞list集合后臺(tái)springmvc接收
這篇文章主要介紹了使用postman傳遞list集合后臺(tái)springmvc接收的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08
Java基本數(shù)據(jù)類型與對(duì)應(yīng)的包裝類(動(dòng)力節(jié)點(diǎn)java學(xué)院整理)
Java是面向?qū)ο蟮木幊陶Z言,包裝類的出現(xiàn)更好的體現(xiàn)這一思想,Java語言提供了八種基本類型。六種數(shù)字類型(四個(gè)整數(shù)型,兩個(gè)浮點(diǎn)型),一種字符類型,還有一種布爾型。 下面通過本文給大家詳細(xì)介紹,感興趣的朋友一起學(xué)習(xí)吧2017-04-04
解決Spring Boot和Feign中使用Java 8時(shí)間日期API(LocalDate等)的序列化問題
這篇文章主要介紹了解決Spring Boot和Feign中使用Java 8時(shí)間日期API(LocalDate等)的序列化問題,需要的朋友可以參考下2018-03-03
關(guān)于@ApiImplicitParams、ApiImplicitParam的使用說明
這篇文章主要介紹了關(guān)于@ApiImplicitParams、ApiImplicitParam的使用說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10
java實(shí)現(xiàn)簡單超市管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡單超市管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01
xxl-job對(duì)比ElasticJob使用示例詳解
這篇文章主要為大家介紹了xxl-job對(duì)比ElasticJob使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06

