@[TOC]
preface
Tips for learning Javaweb
Before starting this article, I would like to give some advice to those who want to learn the Java backend, learn Java Web and make a website or Server Application by themselves. Because of my own learning path, those who have read my blog a long time ago will have some impression that I started from Python crawler, infiltrated, then played Django, then played Java this set of system. Because I’ve also played mathematical modeling, SO I have a little bit of experience with that kind of algorithm, with machine learning, neural networks, so I’m not here as a beginner.
Always remember, use it before you understand it. Many tutorials like to say that you learn JSP from the bottom up, from serlvet. First of all, these are old technologies, you can use them but not recommended, because you usually use SpringBoot, or SpringMVC which I guess you don’t use much, configuration disaster. I am not saying that this technique is not important, because the following techniques are optimized for this, but as a beginner you should not focus on this first! Instead, experience the process first, familiarize yourself with the process, and then learn from the top down.
What Java Web is in my mind is a tool that can help developers with Web development, but in many tutorials it refers to Java EE (servlet), followed by Spring MVC and so on. Many videos of learning institutions on site B are also marked in this way, but I think this is not appropriate. Of course, if it is due to some historical reasons, forget it.
Having said that, I hope that for starters, there’s no need to waste time on servlet JSPS, because you’ll find that you’ll almost never see them later on in your studies. (You can’t do that if you have to tear down the bottom layer, but you’ll have something better to use that doesn’t work so well. MVC designers are better than you and I are) so my advice is to skip the servlet, which is Java Web in most of the videos.
Skip the Java web
By Java Web, I mean servlets, JSPS, etc. Yes, go straight to Spring, but make sure you know your basics (multithreading, XML, Maven, reflection, annotations, basic design patterns, front-end basics) before you start. You don’t need to learn too much about Spring. Remember that you’re just a beginner. After basic use of Spring, please go to learn Springboot, and then mybatis, MVC are based on Springboot learning.
Relationship between SpringBoot and Spring
Many people may not know the relationship between them, so I will tell you first, and also tell you why you need to learn Spring first. The first thing spring does is IOC, container management, which includes object management, dependency transfer, dependency injection, and design patterns, and then AOP. Those of you who have seen my work on Spring 5 should know that you don’t know, but you should know that. The second thing is database support. Springjdbctemplate provides support for database transactions and database operations. Springjdbctemplate supports only one database, and also supports extensions such as Mybatis. And then the third thing is Java Web support, which, like JDBC directly, people don’t think is “elegant”, so of course there is support, and you wrap it up, and you end up with SpringMVC, and yes SpringMVC is actually a Module of Spring, So many people say that Spring is a big family. Although Spring is very powerful, the problem is that it supports a lot of things, but it means that the configuration is very difficult. Imagine how difficult it is to bind to Tomcat every time you create a project (that’s just one of them). So to optimize the configuration, SpringBoot was born! One of the great things springBoot does is automate configuration, so if you use SpringBoot you’ll be learning more about the technology, understanding the development process, and developing your own little demos quickly. Current cloud services are also based on SpringBoot and SpringCloud. So learning about SpringBoot, for example, making websites out of SpringBoot, the apis that you actually use are all in SpringMVC, so you can kind of think of learning about SpringBoot as learning about the use of Spring SpringMVC and other integrated frameworks, It’s just that under normal circumstances, you still need to learn the configuration between them (this may depend on the face).
After the ticket
Said so much, in front of the premises and the objective is to help small white learn quickly, but after learning, we have to begin to go back, back to the Java web learning, this time, you could look at, why was there such operation, because the original and so on, at this time of the study was not to use it to work, Rather, to understand the “primitive” set of operations (remember that this is not low-level, it does not even go to the socket level), to learn retrospectively, so as to understand, for example, springBoot configuration, exactly what is done. What did you do? That way, if something goes wrong in the future, you’ll be able to react quickly.
So the reason why I write this blog is also a make-up ticket ~
When to make up
So the question is, when do you pay for it? The answer is simple, when you can go and make something yourself with Springboot, For example, at the end of my sophomore year, THE Evildoers (SpringBoot+Vue) also used Vue. The first generation was written by Django. But as long as you can make something similar, that is, almost, to pay for the ticket. Of course, you can learn SpringBoot directly, but I recommend learning the basics of Spring first.
In fact, when the make-up ticket, you will find it is very easy, because how to use you understand the ya.
But here if you want to go a bit further, here the extra ticket can also be with the source reading ~ we can not only use it, such a training class catch a big, so as an interviewer, as a formula I with what to you!
Environment to prepare
With all that said, let’s get started.
Download Tomcat
First of all, there are many ways to create Java Web. We are using Maven here, but you can be sure to use Tomcat because servlets are microapplications of Tomcat. They are written in Tomcat and run in A WAR package. Tomcat is a server.
Download and decompress the official website directly
Chinese garbled
Since mine is in Windows, there is something wrong with the encoding, so Chinese may output gibberish in the console. The solution is as follows: Find this file in your TomcatEdit and enter this
java.util.logging.ConsoleHandler.encoding=GBK
Copy the code
And then save
Create a project
It’s also easy to create projects. Create Maven projectsAll the way to Next, type in your own project name so I don’t have to say anything
Configure Tomcat
Now I’m going to do the more important step and let’s just watch what I do.
Import Servlet dependencies
Sometimes, if you have an annotation directly, you might find that the @webservlet () annotation doesn’t have one! That’s the dependency you haven’t imported yet, so do that
Now that it’s all right, let’s test it out
test
Let’s write a test classAnd then go into our browser
You can see that everything is normal
Configuration details
There are a few configuration details here, mainly for Tomcat I think the other ones are pretty clear on the panel, so I won’t go into them here.