最适合初学者的简单JAVAWEB项目快速入门(A quick start to a simple JavaWeb project most suitable for beginners)

最近学习了一段时间JavaWeb,但做项目一直做不出来。相信很多初学者都有和我一样的问题,即为什么我学了,但我不会做?以及如何做一个简单的Web项目?对于初学者来说,我感觉可能从我,一个初学者角度来回答这个问题最合适。以下是我的想法:

我自己反思得出的结果如下,

为什么学了不会做项目:

一、对要学习的技术不了解,导致这学一点,那学一点,最后做了许多无用功,还哪也不精通

二、对学习的技术不会应用,比如我学了SQL语句,我不知道应该写在代码的哪个部分

三、学习内容没有串起来,比如我jdbc连接数据库会了,servlet学了,jsp也看了,但怎么连起来,我不会。

同时,我自己也给出了解决办法:

对于第一点和第二点,我总结了一下,即做一个web需要的技术和目的和要达到的程度:

  一是环境的安装配置,

    1.下载数据库和数据库可视化界面软件,可视化界面软件是为了方便最开始连接数据库前的建表,学习SQL语句是为了写在代码里实现增删改查的操作。如:我学习的数据库是MySQL,用的可视化界面软件是SQLyog。注意:下载数据库是记得下载驱动,以后JDBC连接数据库就不用再下载驱动了!

    2.下载服务器Tomcat,使用Tomcat可以让你的页面在浏览器运行。

    3.下载eclipse javaee版,方便开发web项目(注意:eclipse javase版也可以,但需要下载插件。另外开发工具有许多,不一定非要eclipse,我只是举例)。另外,一定要注意:ee版选择动态web项目后,Tomcat等是配置好的,不需要再配置,再配置也会报端口号占用的错误!

    下载完了后要知道如何使用配置。数据库在SQL学习时会学到,Tomcat可以网上搜如何配置,eclipse可以网上搜如何建立动态web项目。

  二是学习Java,JAVAWEB肯定要会java代码啊,其实servlet等都是Java类,而且自己的数据要封装也是Java的知识,总之,用到Java的地方太多了。至少顺序、选择、循环三大结构、方法、数组、字符串、类与对象、异常要会。

  三是数据库的使用,要学习数据库SQL语句和数据库可视化界面的操作。目的在下载时已经提到。需要可以熟练的用SQL语句操作数据库并且可以用可视化界面软件熟练地操作数据库。

  四是JDBC连接数据库,此处学习是为了知道怎样连接数据库,方面以后增删改查的操作连接到数据库来增删改查。需要知道并可以熟练使用JDBC的API,即DriverManager、PreparedStatement、Connection、ResultSet。

  五是前台页面的设计,此处选择很多,着急过一遍web流程可以先选择一个学习,如HTML,jsp等。需要可以设计前台页面,并且可以看懂别人的模板。

  六是学习servlet,servlet是为了接受前台的命令,并调用后端方法来执行前端需要的操作。学习servlet需要可以熟练的改写doGet和doPost方法,来达到我们的目的。

另外就是问题三,知识我都学了,但怎么串起来呢?其实,以上内容都学完了,还不会做项目,就是学的知识没有串起来。没有串起来我认为原因还是两点,一是不知道学了要干什么,但是这个问题上文已经解决了。二是没有做过项目,只有理论基础,没有实际操作。这个问题最好说了,怎么办?实践呗!

当然,说起来容易做起来难,我认为这是最难的一步了。做项目要思考从哪开始做,是前端到后端还是后端到前端等等,很多种实现方法。还有要怎么分层,怎么建类和包…当然,初学者可以先思考,等做的多了,就都想通了。现在最紧要的,是开始实践,做一个小的web项目。那么,这就跳到第二个问题了,如何做一个简单的web项目。

以及如何做一个简单的Web项目:

首先,我认为最重要的是分层,要知道在那个文件里建立bean/dao/service/servlet层,在那个文件里存放驱动包,在那个文件里放前端页面,我认为这些问题也就是所谓的串起来。我是根据B站的视频学习的,这是我学习的视频:https://www.bilibili.com/video/BV18s411u7EH?p=23,23,24两节分别讲了MVC模式和三层架构,并且都带着做了项目,我觉得没有做过可以跟着做一做。当然,也不一定非要看视频,也可以网上搜索别人的项目,如:学生管理系统,人口普查系统等等,我推荐那些带有目录的项目,这样就可以更好的理解如何分层了。我学习的时候不光看视频,也看别人的项目,看别人的项目的优点在于可以复制,可以快速理解分层,但对内部代码具体细节等会忽略。而且基本上没有详细说分层的,大多是代码一放,你爱看不看。看视频就对分层印象比较深了,而且自己敲过,细节更了解。但视频不能复制,只能自己敲,没敲完前,对大框架可能理解不够透彻。随后我会把我的代码和目录发表,大家可以再看一看,想一想。

其次就是代码内部细节了,只要前面学的扎实,这里一般是没有问题的。

另外:

以上只是说了一下大体框架,要想做好一个项目,对每个技术的理解都要到位,不能只图快,我说了SQL语句要学啥,就直接去看我说什么SQL语句如何建表等等的,但其实数据库是啥都不知道,这种行为,肯定是不行的。而且,实践过程中,肯定会遇到各种bug,如Tomcat报404,页面乱码等等,这些都需要自己搜索解决,也是上面没有提到但很重要的。当然,我也只是一个初学者,如果哪里有理解的不对的地方,欢迎大家提出讨论。

最后,在此和大家共勉,希望我们早日做出一个完整的web项目!

————————

Recently, I have studied Java Web for some time, but I can’t do it as a project. I believe many beginners have the same problem as me, that is, why do I learn, but I can’t do it? And how to do a simple web project? For beginners, I think it is most appropriate to answer this question from the perspective of me, a beginner. Here are my thoughts:

The results of my own reflection are as follows,

Why can’t you do a project after learning:

1、 Lack of understanding of the technology to be learned leads to learning a little, learning a little, and finally doing a lot of useless work and not being proficient at anything

2、 I won’t apply the learned technology. For example, I learned SQL statements, and I don’t know which part of the code to write

3、 The learning contents are not linked together. For example, I can connect to the database through JDBC, learn servlet, and read JSP, but I can’t connect them.

At the same time, I also gave the solution:

For the first and second points, I have summarized the technology, purpose and degree of being a Web:

First, the installation and configuration of the environment,

1. Download the database and database visualization interface software. The visualization interface software is to facilitate the creation of tables before connecting to the database. Learning SQL statements is to write in the code to realize the operation of adding, deleting, modifying and querying. For example, the database I studied is mysql, and the visual interface software I used is sqlyog. Note: remember to download the driver when downloading the database. In the future, you don’t have to download the driver when connecting to the database through JDBC!

2. Download the server Tomcat. Using Tomcat can make your page run in the browser.

3. Download eclipse   Java EE version, easy to develop web projects (Note: eclipse)   Java SE version is OK, but you need to download plug-ins. In addition, there are many development tools, not necessarily eclipse. I’m just giving an example). In addition, it must be noted that after the dynamic web project is selected in the EE version, Tomcat and others are configured. There is no need to reconfigure, and the port number occupation error will be reported in the reconfiguration!

After downloading, you should know how to use the configuration. When learning SQL database, you will learn that Tomcat can search online for how to configure and eclipse can search online for how to establish dynamic web projects.

Second, learn Java. JavaWeb must know java code. In fact, servlets are Java classes, and their own data should be encapsulated. In short, there are too many places to use Java. At least three structures, methods, arrays, strings, classes and objects, and exceptions, such as sequence, selection, and loop, shall be met.

The third is the use of database. We should learn the operation of database SQL statement and database visual interface. The purpose has been mentioned at the time of download. Need to be able to skillfully operate the database with SQL statements, and can skillfully operate the database with visual interface software.

Fourth, JDBC connects to the database. The purpose of learning here is to know how to connect to the database. In terms of the operation of adding, deleting, modifying and querying in the future, connect to the database to add, delete, modify and query. You need to know and be proficient in using JDBC APIs, namely drivermanager, Preparedstatement, connection and resultset.

Fifth, the design of the front page. There are many choices here. If you are anxious to go through the web process, you can choose one to learn first, such as HTML, JSP, etc. Need to be able to design the front page and understand other people’s templates.

The sixth is to learn servlet, which is to accept the commands from the front end and call the back-end methods to perform the operations required by the front end. Learning servlet requires skillfully rewriting doget and dopost methods to achieve our goal.

The other is question 3. I have learned all the knowledge, but how can I string it together? In fact, after learning all the above contents, I still can’t do the project, that is, the knowledge I learned is not connected. I think there are two reasons for not connecting them. First, I don’t know what to do after learning, but this problem has been solved above. Second, there is no project, only theoretical basis, no practical operation. This is the best question. What should I do? Practice!

Of course, it’s easier said than done. I think this is the hardest step. When doing a project, we should think about where to start, whether it is front-end to back-end or back-end to front-end, and so on. There are many implementation methods. And how to layer, how to build classes and packages… Of course, beginners can think first. When they do more, they will figure it out. The most important thing now is to start practicing and do a small web project. So, this jumps to the second question, how to do a simple web project.

And how to do a simple web project:

First of all, I think the most important thing is layering. You should know that the bean / Dao / service / servlet layer is established in that file, the driver package is stored in that file, and the front-end page is placed in that file. I think these problems are the so-called string. I learned from the video of station B. This is the video I learned: https://www.bilibili.com/video/BV18s411u7EH?p=23 In sections 23 and 24, we talked about MVC mode and three-tier architecture respectively, and we have done projects with them. I think we can follow them if we haven’t done so. Of course, you don’t have to watch videos. You can also search other people’s projects online, such as student management system, census system, etc. I recommend those projects with directories, so that you can better understand how to layer. When I study, I not only watch videos, but also watch other people’s projects. The advantage of watching other people’s projects is that they can be copied and can quickly understand layering, but I ignore the specific details of internal code. And basically there is no detailed description of layering. Most of them are code. Do you like to see it. After watching the video, I was deeply impressed by the layering, and I knocked it myself, so I know more about the details. But the video can’t be copied. You can only knock it yourself. Before you knock it out, you may not have a thorough understanding of the large framework. Then I will publish my code and directory. You can have a look and think again.

The second is the internal details of the code. As long as you learn well, there is generally no problem here.

In addition:

The above just talks about the general framework. To do a good job in a project, you should have a good understanding of each technology. You can’t just try to be fast. When I say what SQL statements to learn, you can directly see what SQL statements I say, how to build tables, etc., but in fact, you don’t know what the database is. This behavior must not work. Moreover, in the process of practice, we will certainly encounter various bugs, such as Tomcat report 404, page garbled code and so on. These need to be solved by our own search, which is not mentioned above but very important. Of course, I am just a beginner. If there is anything wrong with my understanding, you are welcome to discuss it.

Finally, I would like to encourage you to make a complete web project as soon as possible!