Java +tomcat + SPRINGMVC for page access

Source: Internet
Author: User

2018-07-18 14:38:29
WINDOW7 installation Record of Java environment:
First, install Tomcat
1, download Tomcat 7.0, unzip, no installation, put to directory: D:\apache-tomcat-7.0.90.
2, configure the system environment variable, catalina_base=d:\apache-tomcat-7.0.90,catalina_home=d:\apache-tomcat-7.0.90, add "%CATALINA_HOME" in Path %\lib;%catalina_home%\bin "Environment variable.
3. Enter D:\apache-tomcat-7.0.90\bin, execute startup Tomcat, enter "127.0.0.1:8080" in the browser to see if it is successful.
Second, use SPRINGMVC build page
1, use idea to create SPRINGMVC project, WebAppTest2

2, modify the Web/web-inf/web.xml URL rule to accept All

<?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>c Ontextconfiglocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> & Lt;/context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlisten er</listener-class> </listener> <servlet> &LT;SERVLET-NAME&GT;DISPATCHER&LT;/SERVLET-NAME&G        T            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:dispatcher-ser Vlet.xml</param-value>        </init-param> </servlet> <servlet-mapping> &LT;SERVLET-NAME&GT;DISPATCHER&LT;/SERVL Et-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>

3. Create a dispatcher-servlet.xml file under src

<?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 Packa GE--<context:component-scan base-package= "test"/> <!--don ' t handle the static resource--&LT ; Mvc:default-servlet-handler/> <!--If you use annotation you must configure following setting--&LT;MVC : Annotation-driven/> <!--Configure the Internalresourceviewresolver--<bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "id=" Internalresourceviewresolver "> & lt;! ---prefix---<property name= "prefix" value= "/web-inf/jsp/"/> <!--suffix--<property na Me= "suffix" value= ". jsp"/> </bean></beans>

4. Create the test directory under SRC and create the Mycontroller file in the directory.

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. Create the classes and Lib folders under Web/web-inf to set the compiled. class file directory and the third-party dependency package directory.

6. Create the JSP directory under web/web-inf/and create the hello.jsp in the directory

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

7, Fight the war package Build-->build artifacts, package name WebAppTest2, put into the D:\apache-tomcat-7.0.90\webapps directory.
8. Restart Tomcat to access Http://127.0.0.1:8080/webAppTest2/mvc/hello.

9, can also set idea built-in Tomcat, direct idea within the launch browser


10, omit the project name, direct Access can

Java +tomcat + SPRINGMVC for page access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.