分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

IDEA--IDEA配置web项目

发布时间:2023-09-06 02:28责任编辑:顾先生关键词:配置

参考:https://blog.csdn.net/kfm1376822651/article/details/79666586

记学习springmvc时,使用idea部署web项目至tomcat.

新建模块springmvc(spring mvc项目)

将springmvc模块置于maven下管理

添加相关依赖

配置DispatcherServerlet,添加一个controller及其jsp

配置文件

删除自动生成的相关配置,这里使用的是java config方式来配置DispatcherServlet及其他配置.

 配置artifacts

配置Tomcat

运行

OJBK

相关代码,来源于spring action -- spring mvc.

1 package org.wzh.three2.springmvc;2 3 import org.springframework.context.annotation.ComponentScan;4 import org.springframework.context.annotation.Configuration;5 6 @Configuration7 @ComponentScan8 public class RootConfig {9 }
 1 package org.wzh.three2.springmvc; 2 ?3 import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 ?5 public class SpittrWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 6 ?7 ????static { 8 ????????System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); 9 ????????System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");10 ????????System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");11 ????}12 13 ????@Override14 ????protected Class<?>[] getRootConfigClasses() {15 ????????return new Class<?>[] { RootConfig.class };16 ????}17 18 ????@Override19 ????protected Class<?>[] getServletConfigClasses() {20 ????????System.out.println("------");21 ????????System.out.println("init servlet config classes");22 ????????return new Class<?>[] { WebConfig.class };23 ????}24 25 ????@Override26 ????protected String[] getServletMappings() {27 ????????return new String[] { "/" };28 ????}29 }
 1 package org.wzh.three2.springmvc; 2 ?3 import org.springframework.context.annotation.Bean; 4 import org.springframework.context.annotation.ComponentScan; 5 import org.springframework.context.annotation.Configuration; 6 import org.springframework.web.servlet.ViewResolver; 7 import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; 8 import org.springframework.web.servlet.config.annotation.EnableWebMvc; 9 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;10 import org.springframework.web.servlet.view.InternalResourceViewResolver;11 12 @Configuration13 @EnableWebMvc14 @ComponentScan15 public class WebConfig extends WebMvcConfigurerAdapter {16 17 ????@Bean18 ????public ViewResolver viewResolver() {19 ????????InternalResourceViewResolver resolver = new InternalResourceViewResolver();20 ????????resolver.setPrefix("/WEB-INF/views/");21 ????????resolver.setSuffix(".jsp");22 ????????resolver.setExposeContextBeansAsAttributes(true);23 ????????return resolver;24 ????}25 26 ????@Override27 ????public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {28 ????????configurer.enable();29 ????}30 }
 1 package org.wzh.three2.springmvc.controller; 2 ?3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RequestMethod; 6 ?7 @Controller 8 public class HomeController { 9 10 ????@RequestMapping(value = "/home", method = RequestMethod.GET)11 ????public String home() {12 ????????System.out.println("ENTER HOMECONTROLLER..");13 ????????return "home";14 ????}15 16 }
 1 <%-- 2 ??Created by IntelliJ IDEA. 3 ??User: Pear 4 ??Date: 2018/12/25 5 ??Time: 21:53 6 ??To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 <html>10 ??<head>11 ????<title>$Title$</title>12 ??</head>13 ??<body>14 ??$END$15 ??</body>16 </html>

具体部署位置:

IDEA--IDEA配置web项目

原文地址:https://www.cnblogs.com/microcat/p/10199795.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved