java tomcat spring_Java +Tomcat + SpringMVC实现页面访问示例解析

window7下Java环境安装记录:

一、安装Tomcat

1、下载tomcat 7.0,解压,无需安装,放置到目录:D:\apache-tomcat-7.0.90。

2、配置系统环境变量,CATALINA_BASE=D:\apache-tomcat-7.0.90,CATALINA_HOME=D:\apache-tomcat-7.0.90,在Path中新增“%CATALINA_HOME%\lib;%CATALINA_HOME%\bin”的环境变量。

3、进入D:\apache-tomcat-7.0.90\bin,执行startup启动tomcat,浏览器中输入“127.0.0.1:8080”即可查看是否成功。

二、使用SpringMVC搭建页面

1、使用Idea创建SpringMVC工程,webAppTest2

78f55ba925d2e281418bde83f2a48769.png

2、修改web/WEB-INF/web.xml的url规则为接受所有

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

contextConfigLocation

/WEB-INF/applicationContext.xml

org.springframework.web.context.ContextLoaderListener

dispatcher

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:dispatcher-servlet.xml

dispatcher

/

3、在src下创建dispatcher-servlet.xml文件

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

id="internalResourceViewResolver">

4、在src下创建test目录,目录下同时创建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下创建classes和lib文件夹,用来设置编译的.class文件目录和第三方依赖包目录。

7970759eb19f2bf592d73ace3fd92a87.png

6、web/WEB-INF/下创建jsp目录,并在目录下创建hello.jsp

Title

Hello world!!!!

7、打war包Build-->Build Artifacts,包名webAppTest2,放到D:\apache-tomcat-7.0.90\webapps目录下。

8、重启tomcat,访问http://127.0.0.1:8080/webAppTest2/mvc/hello即可。

4faf08fb3f4132b63ad47f9333df76c0.png

9、也可以设置Idea内置Tomcat,直接Idea内启动浏览器

f720e0470b16bb7b311a5e68622519fe.png

77b2f3c635c97ea3d5782bff9e50239f.png

10、省略工程名,直接访问即可

892194475501e148fd5357481b58acdb.png

到此这篇关于Java +Tomcat + SpringMVC实现页面访问示例解析的文章就介绍到这了,更多相关Java  Tomcat  SpringMVC 页面访问内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值