2018-07-18 14:38:29
window7下Java環境安裝記錄:
1、安裝Tomcat
一、下載tomcat 7.0,解壓,無需安裝,放置到目錄:D:\apache-tomcat-7.0.90。
二、配置系統環境變量,CATALINA_BASE=D:\apache-tomcat-7.0.90,CATALINA_HOME=D:\apache-tomcat-7.0.90,在Path中新增「%CATALINA_HOME%\lib;%CATALINA_HOME%\bin」的環境變量。
三、進入D:\apache-tomcat-7.0.90\bin,執行startup啓動tomcat,瀏覽器中輸入「127.0.0.1:8080」便可查看是否成功。
2、使用SpringMVC搭建頁面
一、使用Idea建立SpringMVC工程,webAppTest2
二、修改web/WEB-INF/web.xml的url規則爲接受全部html
<?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>
三、在src下建立dispatcher-servlet.xml文件java
<?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>
四、在src下建立test目錄,目錄下同時建立MyController文件web
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"; } }
五、在web/WEB-INF下建立classes和lib文件夾,用來設置編譯的.class文件目錄和第三方依賴包目錄。
六、web/WEB-INF/下建立jsp目錄,並在目錄下建立hello.jspspring
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> Hello world!!!! </body> </html>
七、打war包Build-->Build Artifacts,包名webAppTest2,放到D:\apache-tomcat-7.0.90\webapps目錄下。
八、重啓tomcat,訪問http://127.0.0.1:8080/webAppTest2/mvc/hello 便可。
九、也能夠設置Idea內置Tomcat,直接Idea內啓動瀏覽器
十、省略工程名,直接訪問便可apache