- 問(wèn)題描述一:老項(xiàng)目jsp都是在WebContent目錄下祖今,servlet在web.xml中配置,而springboot項(xiàng)目這二個(gè)目錄都不存在千诬。
- 問(wèn)題描述二、如何將已有javaweb項(xiàng)目改造為Spring Boot項(xiàng)目
老項(xiàng)目項(xiàng)目結(jié)構(gòu)
一、jsp頁(yè)面的問(wèn)題
新建一個(gè)代碼目錄(【New】->【Source Folder】)泵三,命名為src/main/webapp烫幕,將原項(xiàng)目中WebContent目錄下的所有內(nèi)容拷貝至該目錄內(nèi)
idea下可mark directory ar Sources Roor
將jsp頁(yè)面放進(jìn)去之后,需要加上jsp的依賴(lài)
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!--http://www.it399.com/-->
<!--加入支持JSP的依賴(lài)-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
不然就會(huì)出現(xiàn)如下jsp頁(yè)面不能被解析
圖片.png
二磷斧、servlet映射問(wèn)題
之前servlet寫(xiě)在web.xml里面捷犹,但是springboot里面不識(shí)別web.xml,所以使用注解配置映射關(guān)系:
import com.it399.tools.itext.house.HouseImageServelet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ServletConfigure {
/**
* 代碼注冊(cè)servlet
* @return
*/
@Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new HouseImageServelet(), "/houseImage");// ServletName默認(rèn)值為首字母小寫(xiě)侣颂,即myServlet1
}
// /**
// * 多個(gè)servlet就注冊(cè)多個(gè)bean
// * @return
// */
// @Bean
// public ServletRegistrationBean servletRegistrationBean1() {
// return new ServletRegistrationBean(new MyServlet(), "/servlet/myServlet");// ServletName默認(rèn)值為首字母小寫(xiě)枪孩,即myServlet
// }
}
這樣就可以訪問(wèn)了,測(cè)試地址:在線助手|在線工具|在線生成|在線制作
http://www.it399.com/myHouse.jsp
本文同步發(fā)布在 在線助手|在線工具 拒担,轉(zhuǎn)載請(qǐng)注明來(lái)自 在線助手博客頻道【解決springboot web項(xiàng)目在windows eclipse中可以啟動(dòng)在IntelliJ IDEA中報(bào)錯(cuò) Mac idea正彻パ】,原文鏈接:http://www.it399.com/blog/web/201805031726