The problems that Eclipse has encountered in changing the Modle1 and Model2 architectures to the MVC architecture development JSP

Source: Internet
Author: User

Here is just a summary of my problems, recently in the use of Eclipse learning JSP Development, the beginning of the use of Model1 architecture to write a lot, and gradually also found modle1 problems, In particular, the HTML and Java fragment Mix is not clear and for the database operation every time to re-write the code is very troublesome, and then encountered Model1+class that is MODEL2 architecture, the whole change, feel a pattern after the idea is very clear, But want to complete my project feeling also lacks a little, so found the MVC architecture, but in the use of servlet as controller conversion before the code encountered problems, there are all kinds of problems, originally thought can be done in a few minutes, but there are all kinds of bugs, the results of a half a day to finish. All right, no more nonsense, now to sum up ~

The first one is 404, this is almost from beginning to end, follow me, first of all, let's look at my project's file structure, that is, because this file structure led me to meet a variety of problems, but, obsessive-compulsive people can not hurt Ah, I just want to put all the files are loaded into the corresponding folder:


I created a new Web folder and then set up the corresponding folder below, all my JSP files are under the JSP folder. The servlet was created directly at the beginning, but the test was directly 404, The last two looked up and said that the Web. XML configuration is not right, look back, I actually did not have web. XML, (oh oh, the above diagram is a later figure), but in my new servlet class above see this thing:



So I looked it up, and it turned out that this is Serlvet3.0 's new feature annotation @WebServlet, said this simple and convenient, I also learn to accept the new technology and learn the parameters, and then know Urlpatterns is responsible for the corresponding servlet address changed to Urlpatterns = {"/web/jsp/checkuser"} (CheckUser is my servlet class) but it has no effect ( Finally, according to the problem I found changed the package name and path also did not succeed ... )。 Then I saw a lot of questions and answers, so a web. Xml then set up a test file to add the Web. XML Actually, this is very simple when creating the project:


See the check box below? Hook on it, and finally the Web. XML is then created with a servlet file, but the corresponding Web. XML is not automatically configured as they say, and is always the interface:


There is no change, later found that the original is servlet3 before the automatic configuration, so, and the project to change into a servlet2.5, I do not have any good method has been built as follows:


Look at that drop-down list you can choose, so, finally configured, and then the inside of the path changed ( see that url-pattern):


But there is a new problem is the HTTP Status 500-error instantiating servlet class and then the page refreshed it into 404, I was a moment blindfolded, and then began to check, but everyone is saying that the package configuration is wrong, But I have this package automatically configured AH? How can it be wrong? Then I was impatient, and I changed my package name from level three to level two (because I used to write Java when it was com.exapmle.xxx, so here is also customary to write this) as follows:


Then changed to Src.servlet and then in the Web. XML inside changed after the test, unexpectedly OK ~


And then I guess that's what I'm building. I thought it was a three-level structure, but the compiler might think my com.tools is just a name, and there are. This glyph can cause confusion.

OK, of course, this is limited to people like me with obsessive-compulsive disorder, if you do not mind directly under the webcontent to build JSP, there will not be so many problems ~

Perhaps, my problem-solving process has gone a lot of detours, but also please point out, if any great God can solve this problem under the Servlet3, but also share the method ha ~



The problems that Eclipse has encountered in changing the Modle1 and Model2 architectures to the MVC architecture development JSP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.