Example of using JSP in spring boot practice

The front-end and back-end separation architecture has its advantages, but according to the specific situation, it is not appropriate to use the front-end and back-end separation architecture at any time. I recently realized the pitfalls. Due to the problem of department attributes, the front-end projects account for a relatively low proportion, so the front-end of the company are basically novices. As a result, the back-end interface has been completed for more than a month, and the front-end is still working overtime. The capacity and number of front and rear end personnel match the workload. When the front and rear ends can hold, it is recommended to use the front and rear end separation architecture. If the front end capacity is limited or there are few personnel, it is best not to use it, so as to ensure that the project progress can be controlled.

Spring boot does not recommend using JSP, but there may be restrictions on habits and personnel knowledge. If you still want to use JSP, you can learn how to use JSP in spring boot projects according to the following tutorial.

1. Add Maven dependency

2. Add configuration

In application Add the following configuration in properties:

3. Create JSP

Create the Src / main / webapp / WEB-INF / JSP directory without changing the directory structure

Create a static directory under Src / main / resources directory to store static resources, such as image directory for pictures and JS directory for JS files

Create a JSP file, such as test jsp

${pagecontext. Request. Contextpath} is used to get the project path, that is, server Value of context path setting

Visit picture ${pagecontext. Request. Contextpath} / image / 1 Jpg, which is Src / main / resources / static / image / 1 JPG file, pay attention to direct access to / image / 1 Jpg is enough

The loading JS path is ${pagecontext. Request. Contextpath} / JS / jQuery Min.js, which is similar to the way of loading static resources in pictures

4. Access JSP

Create controller

After starting the project, visit localhost: port / test to see the sample page above.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>