Intermediary transaction SEO diagnosis Taobao guest Cloud host technology Hall
In the recent course design, we are required to use the Struts framework and the Hibernate framework to complete a student elective system. Many students complain about not learning the two frameworks and complain about why they don't use the MVC pattern because they already know the MVC.
So I have to say that there are two modes of JSO Web development.
Mode1
Simply put, the Mode1 pattern is also divided into two situations, one that is developed entirely using JSP and the other is developed using Jsp+javabean. The only advantage of both schemes is that it is suitable for small web development, such as a simple personal homepage, and using the MODE1 mode is your preferred option.
Of course, if your project is small enough to use pure JSP to develop, so that your maintenance will be easier. Because it eliminates the hassle of modifying JavaBean, you need to recompile to ". Class" files.
And the shortcomings of Mode1 can not be neglected, in the development process, a large number of logic processing code in the JSP and JavaBean, which led to increased complexity of the javabean, increased relevance (also called coupling), we are in the pursuit of perfect development is "high cohesion low coupling", So in the development of large-scale projects, we will still leave the Mode1 mode aside.
MODE1 schematic
Mode2
Mode2 is a servlet as the main body, through the servlet to accept customer requests, call different JavaBean processing, return the results to the JSP page, so clear division of labor, efficiency, and facilitate project maintenance, is the first choice for large-scale website construction. In Mode2, there is a design pattern called MVC. The design pattern is divided into model layer, display layer and control layer.
MVC design Pattern
So understanding MVC and struts
If you find it hard to understand what MVC and struts are all about, you can argue that MVC is a defined standard interface (interface), and that struts is the perfect implementation of the MVC interface. Besides STRUTS,EJB is also an implementation of MVC.
The combination of struts and hibernate
It is not difficult to understand that struts is used to get form data in the entire "Student selection system" design process, hibernate is used to persist objects to the database. The basic design process is:
One: interface design, first of all you need to the front page structure perfect, give users a good impression.
This is the front landing interface I designed.
Second: Consider the persistence layer: In the current project, "Student elective system" when students mainly, each student can choose more than one subject, so there is a one-to-many relationship, in the hibernate use of tags to map the relationship. The export mapping is related to the database. You can persist object relationships to a database.
Three: Struts process: through struts to obtain form data, and then by calling Hibernate HQL statements for data validation, is the key to landing verification. After the whole system has been modified, I will post the specific code for your reference. For the verification of the foreground data, I did not use JavaScript and was using the Validaate validation framework of struts, if you do not understand this, you can refer to <>.
About hibernate and MySQL coding issues
Coding problems are the most maddening problem, using hibernate in Chinese characters, and the database does have a bunch of "???" Annoying. What we need to do is to encode the unity. and "UTF-8" encoding advantage I do not say, it can support the noon code display, so we are in the construction of the database, the last manually set mode encoding, CREATE database test DEFAULT Charset=utf8.
Then what needs to be modified is the hibernate encoding. Programme I:
In the "Hibernate.cfg.xml" file, you should write the "URL" configuration as follows:
XML Code
<property name= "Connection.url" >jdbc:mysql://localhost:3306/test?useunicode=true&characterencoding= Utf-8</property>
Programme II:
1, the MySQL installation when setting the character set Utf-8 (including the database character set, and the table character set), JDBC driver with the latest.
2.hibernate configuration file (Hibernate.cfg.xml), plus properties
XML Code
<property name= "Connection.useunicode" >true</property> <property name= " Connection.characterencoding ">UTF-8</property>
3. Web.xml Set Filter
XML Code
<filter> <filter-name> Set Web creator Character Encoding </filter-name> <filter-class> Com.util.setencodefilter</filter-class> <init-param> <param-name>defaultencoding</ param-name> <param-value>UTF-8</param-value> </init-param> </filter> < filter-mapping> <filter-name> Set Web creator Character Encoding </filter-name> & nbsp; <url-pattern>/*</url-pattern> </filter-mapping>