단계 서문 후, 인 IntelliJ의 IDEA와 다운로드에 톰캣 클라이언트, 서버 다운로드를 설치하고 설치, 이들은 완성 된 구성이
프로젝트를 만들 준비
다음을 클릭합니다.
프로젝트 이름은 같은 이름을 가진 다른 프로젝트의 이름을 수정 종료, 나도 같은 프로젝트 이름 이름에 관련된 다른 저장 위치를 변경, 항아리 패키지를 다운로드합니다이 프레임 워크 필요를 마침을 클릭합니다
창조 인터페이스의 업적 후
추가 폴더 JSP, 클래스, LIB, 정적 (CSS, 이미지, JS)
여기에 경로 폴더 프로젝트 클래스로 두 경로는
클릭 종속성은 +에서 오른쪽 클릭
첫 번째 선택
여기에 클릭 확인 후 다음과 같은 팝업 페이지 위의 단계 누락
다음으로, 구성 Tomcat은 지금 실행하고 디버그 버튼은 회색이고, 당신은 성공적인 구성을 실행할 수 있습니다 가리킬 수 없습니다
다음 그림 실행 -를 클릭> 편집 구성도의 오른쪽 클릭 할 수 있습니다
아티팩트를 클릭 한 다음 액세스 경로 구성을 아래로 당겨
그런 다음 완료 적용을 클릭합니다
실행 한 후 구성 할 수 있습니다, web.xml에
프롬프트 오류를 실행에 아무 소용이 없다
확인을 다시 실행 한 후
이것은 가장 접근 가능한 외부의 index.jsp를하다
나는 그 안에 액세스 JSP 파일 폴더에 원하는
다음 다음 구성
나는 방법을 작성하는 다음의 서류를 다시 추가
제어기 패키지; 수입 org.springframework.stereotype.Controller; 수입 org.springframework.web.bind.annotation.RequestMapping; @제어 장치 (@RequestMapping " / MVC를 " ) 공공 클래스 HelloWordController { @RequestMapping("/hello") public String hello() { return "hello"; } }
然后配置applicationContext.xml、dispatcher-servlet.xml、web.xml
applicationContext.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" 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"> <context:component-scan base-package="controller"/><!--扫描的包 你自己新建的包名--> </beans>
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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--此文件负责整个mvc中的配置--> <!--启用spring的一些annotation --> <context:annotation-config/> <!-- 配置注解驱动 可以将request参数与绑定到controller参数上 --> <mvc:annotation-driven/> <!--静态资源映射--> <!--本项目把静态资源放在了webapp的statics目录下,资源映射如下--> <mvc:resources mapping="/css/**" location="/WEB-INF/statics/css/"/> <mvc:resources mapping="/js/**" location="/WEB-INF/statics/js/"/> <mvc:resources mapping="/image/**" location="/WEB-INF/statics/image/"/> <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀(如果最后一个还是表示文件夹,则最后的斜杠不要漏了) 使用JSP--> <!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- --> <bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>--> <property name="prefix" value="/WEB-INF/jsp/"/><!--设置JSP文件的目录位置--> <property name="suffix" value=".jsp"/> <property name="exposeContextBeansAsAttributes" value="true"/> </bean> <!-- 自动扫描装配 --> <context:component-scan base-package="controller"/> </beans>
web.xml
<?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_3_1.xsd" version="3.1"> <display-name>Archetype Created Web Application</display-name> <!--welcome pages--> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!--配置springmvc DispatcherServlet--> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <!--配置dispatcher.xml作为mvc的配置文件--> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--把applicationContext.xml加入到配置文件中--> <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> </web-app>
配置好了之后再运行下
运行成功
这个路径配置如下图