Some insights on the implementation of a web project for implementing the MVC framework

zhaozj2021-02-17  43

1. Implement Java's web project needs to be mastered.

Java is not very difficult to speak from a language perspective, but from the overall design perspective belongs to the advanced frame of full object. If you want to design a good frame structure, just master the Java language is not enough. In a framework application is just one of the price adjustments, you want to play a good language, there is a good environmental condition. This involves a design pattern, and some knowledge related to design modes.

Java is a language of the surfactory object, so it is necessary to have a good understanding of the Java application, and the opposite object must have a good understanding. The characteristics and techniques of the Java language itself should be more understood.

In the main applications, there are many ways to be related to the database, so there should be some understanding of the database. You can't just understand a database, because there will be a lot of database solutions in many actual development, so you can only have a comparison plan in the case of a variety of databases, you can't only start from the price, you must undergo the actual needs of the project. To make the best price / performance, this is only a qualified database solution.

There is an important status in many applications, so it is necessary to understand the application server. Includes configuration, application, and implementation. And it is best to understand a variety of application servers and then select the application based on the project requirements.

The server and design mode structure are applied to custom files, and the self-designed label will also be defined when applying advanced design, and now the popularity is defined with XML, so the XML language should have some mastery.

Java is primarily applied to the network, so there must be a certain understanding of the protocol of the network.

In the design of the design web project, the scripting language of the webpage does not overlook the role, so if you design a web project, you should have a certain understanding of HTML and JavaScript.

In summary: A good Java application implementation should be grasped as follows:

Java language, object-oriented ideology, design pattern, frame structure, database, application server, XML language, network protocol, web scripting language.

Second, the choice of tools

In actual development, the development tool directly affects development processes. If you use tools, if it is too complicated, you will have a lot of time before the project development; if the tool is too simple, the development time limit is too large. Therefore, according to the difficulty and intensity of the actual development, it is necessary to do according to the actual situation of the project developer.

The currently used Java project development environment is: JBuilder, Visualage for Java, Forte for Java, Visual Café, Eclipse, NetBeans IDE, JCREATOR J2SDK, EditPlus 2 J2SDK.

It is best to know the advantages and disadvantages of these software to select applications according to the actual situation.

Third, Java language

The Java language system is relatively large, syntax and C are similar. The application perspective has JSP, Applet, Servlet, Application Four parts. In most Web projects, the three parts are mainly applied to JSP, Servlet, Application, and the main application of Application in Web Project Development is JavaBean.

Applet is a program running on the client, excellent in graphic display, it is a program that requires preselection to download to the client. In some development, some design needs to run on the client, then apply Applet, such as NetEase chat. room.

Servlet is a program running on the server, and the ability to handle data is excellent and is a multi-thread design. It is very powerful in the server side.

JSP is a small part of the SERVLET, simplifies development and strengthens interface design. JSP is positioned in the interactive web page. Use Java syntax, but the function is much smaller than servlet, and only serves as the user interface part in advanced development.

Application is a Java application, Java can develop application software like a language such as C , but it is slow to run. The main application of Javabean in the Web project and some development is part of the Application, the logical computing ability is very large, and it can greatly use the Java language. And the package can be applied to the inheritance, polymorphism, and overloaded characteristics of Java, can also be encapsulated. Advanced Web Projects are applied to all of the above technologies, collaborative development will increase the development efficiency and system performance.

Fourth, object-oriented thinking

The Java language is fully object-to-object language, so there is a great help when the project design is designed, and the process-oriented design method should be discarded during design.

When analyzing the project business relationship, apply some ER charts to use a lot of help, which can find the object of the main business logic as soon as possible, and then divide each object. The purpose of final design implementation is to communicate between objects.

"Thinking in Java" has a very classic metaphor, ambiguously compared a light bulb into an object, and then encapsulates the behavior into the object, as shown:

In this example, the name of the type / class is Light, which can be sent to the Light object includes an open (ON), off, becoming brighten, or smother (DIM). By simply declaring a name (LT), we created a "handle" for the Light object. Then instantiate an object of Light with the New keyword. In order to send a message to the object, we list the handle name (LT), and then connect it with a message name (ON) with a period symbol (.). It can be seen from it. When using some predefined classes, our code we use is very simple and intuitive.

V. Design mode

The design pattern is more important in the Java project implementation process. Mainly in two layers of design patterns, three-layer design patterns and N-layer design patterns. Directly determine the application, deployment and actual development design of the project.

Six, frame structure

There are many developing structures in a general web project. JSP Servlet or JSP Javabean. A lot of MVC's three-layer development structure is used in projects that have high development requirements. Separately separated logic development, so that developers can focus on their respective development. At the same time, the entire development structure process is clearer, but it needs a relatively high development complex.

The complete development of MVC is more difficult, and it is necessary to design all the control flows, but not necessarily international development, so in order to simplify the development, improve structure clarity, we can reference the development framework, now the popular MVC development framework is Struct . It can greatly improve the development schedule, improve the structure of the project, but learning Struct also requires a certain amount of time, and the cooperation of XML is required.

The struct focuses on the design of the Controller, divides servlet into both part of the frombean and an ActionServlet. At the same time, the API of the servlet processing is added, including the action, Actionform, ActionMapping class, and the like.

Every FormBean must inherit the Actionform class, and the FormBean is a package requested to page. That is, the HTTP Request package is in an object, and the point to explain is that multiple HTTP Request can share a FORMBEAN to facilitate maintenance and reuse.

The generation of FORMBEAN is to provide data to ActionBean, and data in FormBean can be obtained in ActionBean. After the corresponding logic is processed, the business method completes the corresponding business requirements. The core of Struct is Controller, namely ActionServlet, and the core of ActionServlet is struts-config.xml, and struts-config.xml sets all pages navigation definitions. For large Web projects, you can quickly grasp the context through this profile, whether it is for the early development, or later maintenance or upgrade is very beneficial. Master Struts-Config.xml is the key to master Struts.

The main schematic is as follows:

The Struct framework can be applied to large, medium and small projects. It can greatly improve the quality and efficiency of the MVC model.

Seven, database

For the database, he should understand his performance and some basic operational knowledge, and the characteristics of the database.

Database development for Java language web projects is mainly for JDBC applications, as well as database connection pool applications.

8. Application Server

Like a database, you should understand the performance, characteristics, and some common sense.

In terms of application, the application server is primarily for configuration and deployment, configuring, debugging; modifications to the profile properties; control of access to the concurrency; deployment of Java classes, etc.

There is also an integrated configuration of the server, and the JSP is typically an integrated configuration of Apache Tomcat.

If you are familiar with the XML language, the configuration of the server file is also a huge help of the Java class.

Nine, XML language

From the top, you can see that the XML language is very helpful for web project development, and sometimes there is a key role.

Ten, network protocol

Web project development should have certain levels of application's protocols, so that the knowledge or class library corresponding to the language can be applied.

XI, web scripting language

In order to improve the overall performance of the web project, improve the friendly interface of human-computer interaction, the scripting language of the web page is very useful, and sometimes it can solve a big problem or improve the performance and application of the program.

The execution of the web page scripting language is executed on the client, and the speed is very fast, and most of the operations are not interacting with the server, so it is very ideal in some applications.

Twelve, instance

The process of data delivery of the MVC mode, enter a character from the JSP page, then submit it to the servlet, then call the JavaBean process by the servlet, and then direct the page to another JSP page, and now use session and request two methods.

The JSP page entry page is login.htm, the display page is requestTest.jsp and sessiontest.jsp;

Servlet is TestServlet.class, javabean is TestBean.class, package is com.xinkaidigital.jwing.

code show as below:

Login.htm:

Lomboz JSP </ Title></p> <p></ hEAD></p> <p><body bgcolor = "# ffffff"></p> <p><Form method = "post" action = "servlet / com.xinkaidigital.jwing.testservlet"></p> <p><Input Type = "text" name = "teststr"> <input type = "submit"></p> <p></ Form></p> <p></ body></p> <p></ html></p> <p>TestServlet.class:</p> <p>Package com.xinkaidigital.jwing;</p> <p>Import java.io.ioException;</p> <p>Import javax.servlet.servletconfig;</p> <p>Import javax.servlet.RequestDispatcher;</p> <p>Import javax.servlet.servletException;</p> <p>Import javax.servlet.http.httpservlet;</p> <p>Import javax.servlet.http.httpsession;</p> <p>Import javax.servlet.http.httpservletRequest;</p> <p>Import javax.servlet.http.httpservletResponse;</p> <p>Public class testservlet extends httpservlet {</p> <p>// define charSet</p> <p>Static Final Private String content_type = "text / html; charSet = GBK";</p> <p>Public void init (servletconfig config) throws servletexception {</p> <p>Super.init (config);</p> <p>}</p> <p>Public void destroy () {</p> <p>// Todo Method Stub generated by Lomboz</p> <p>}</p> <p>protected void doget</p> <p>HTTPSERVLETREQUEST REQUEST,</p> <p>Httpservletresponse response</p> <p>Throws servletexception, ioException {</p> <p>Response.setContentType (Content_Type);</p> <p>}</p> <p>protected void dopost</p> <p>HTTPSERVLETREQUEST REQUEST,</p> <p>Httpservletresponse response</p> <p>Throws servletexception, ioException {</p> <p>// define charSet</p> <p>Response.setContentType (Content_Type);</p> <p>// Instance New Object</p> <p>TestBean testbean = new testbean ();</p> <p>// instance session Object</p> <p>HttpSession session = request.getations ();</p> <p>// Request Data</p> <p>String Teststr = Request.getParameter ("Teststr");</p> <p>// use mytest javabean</p> <p>TestBean.Setteststr (Teststr);</p> <p>// define targeturl</p> <p>String targeturl = "/requesttest.jsp";</p> <p>// Add session object</p> <p>Session.setttribute ("SessionBean", TestBean;</p> <p>// Add Request Object</p> <p>Request.setttribute ("Requestbean", TestBean;</p> <p>// Use dispatch to go to jsp</p> <p>THIS.DISPATCH (TargetURL, Request, Response);</p> <p>Public void Dispatch (String Targeturi, HttpservletRequest Request, HTTPSERVLETRESPONSE RESPONSE)</p> <p>Throws java.io.ioException, servletexception</p> <p>{</p> <p>RequestDispatcher dispatch = GetServletContext (). GetRequestDispatcher (Targeturi);</p> <p>Dispatch.forward (Request, Response);</p> <p>}</p> <p>}</p> <p>TestBean.class</p> <p>Package com.xinkaidigital.jwing;</p> <p>Public class testbean {</p> <p>PRIVATE STRING TESTSTR = NULL;</p> <p>Public TestBean () {</p> <p>Super ();</p> <p>}</p> <p>Void setTestStr (String Teststr) {</p> <p>THIS.TESTSTR = Teststr;</p> <p>}</p> <p>Public string getteststr () {</p> <p>Return Teststr;</p> <p>}</p> <p>}</p> <p>Requesttest.jsp:</p> <p><% @ page language = "java" PageEncoding = "GB2312"%></p> <p><! Doctype html public "- // w3c // DTD HTML 4.0 Transitional // En"></p> <p><html></p> <p><HEAD></p> <p><title> RequestBean JSP </ Title></p> <p></ hEAD></p> <p><body bgcolor = "# ffffff"></p> <p><jsp: usebean id = "requestbean" scope = "request" class = "com.xinkaidigital.jwing.testbean" /></p> <p><% = RequestBean.getTestStr ()%></p> <p><Hr></p> <p><Center> <a href="/test/sessiontest.jsp"> sessiontest.jsp </a> </ center></p> <p><Hr></p> <p><Center> <a href="/test/login.html"> index </a> </ center></p> <p></ body></p> <p></ html></p> <p>Sessiontest.jsp:</p> <p><% @ page language = "java" PageEncoding = "GB2312"%></p> <p><! Doctype html public "- // w3c // DTD HTML 4.0 Transitional // En"></p> <p><html></p> <p><HEAD></p> <p><title> sessionBean JSP </ Title></p> <p></ hEAD></p> <p><body bgcolor = "# ffffff"></p> <p><jsp: usebean id = "sessionbean" scope = "session" class = "com.xinkAidigital.jwing.testbean" /> <% = sessionBean.getTestSTR ()%></p> <p><Hr></p> <p><Center> <a href="RequestTest.jsp"> Requesttest.jsp </a> </ center></p> <p><Hr></p> <p><Center> <a href="login.html"> index </a> </ center></p> <p></ body></p> <p></ html></p> <p>An example of a view bean, encapsulates the content displayed to the JavaBean, then call JavaBean in the JSP page.</p> <p>Bean is TestView.class, showing data, the JSP page is</p> <p>code show as below:</p> <p>Viewtest.jsp:</p> <p><% @ page language = "java" PageEncoding = "GB2312"%></p> <p><! Doctype html public "- // w3c // DTD HTML 4.0 Transitional // En"></p> <p><html></p> <p><HEAD></p> <p><Title> ViewBean JSP </ Title></p> <p></ hEAD></p> <p><body bgcolor = "# ffffff"></p> <p><jsp: usebean id = "testview" scope = "page" class = "com.xinkaidigital.jwing.testView" /></p> <p><Hr></p> <p><% TestView.SetView ();%></p> <p><% = TestView.getView ()%></p> <p><Hr></p> <p><Center> <a href="RequestTest.jsp"> Requesttest.jsp </a> </ center></p> <p><Hr></p> <p><Center> <a href="sessiontest.jsp"> sessiontest.jsp </a> </ center></p> <p><Hr></p> <p><Center> <a href="login.html"> index </a> </ center></p> <p></ body></p> <p></ html></p> <p>TestView.class:</p> <p>Package com.xinkaidigital.jwing;</p> <p>Public class testview {</p> <p>// define stringbuffer variable</p> <p>Stringbuffer list = null;</p> <p>Public void setView () {</p> <p>List = new stringbuffer ();</p> <p>List.append ("<Table Width = /" 100% / "Border = /" 0 / "Cellpadding = /" 0 / ");</p> <p>List.Append ("Cellspacing = /" 0 / "BGCOLOR = /" 217dde / ">"); list.append ("<tr>");</p> <p>List.Append ("<TD>");</p> <p>List.Append ("this is a test viewbean1);</p> <p>List.Append ("</ td>");</p> <p>List.Append ("</ tr>");</p> <p>List.Append ("<tr>");</p> <p>List.Append ("<TD>");</p> <p>List.append ("this is a test viewbean2);</p> <p>List.Append ("</ td>");</p> <p>List.Append ("</ tr>");</p> <p>List.Append ("<tr>");</p> <p>List.Append ("<TD>");</p> <p>List.append ("this is a test viewbean3);</p> <p>List.Append ("</ td>");</p> <p>List.Append ("</ tr>");</p> <p>List.Append ("</ Table>");</p> <p>}</p> <p>Public string getView () {</p> <p>Return List.toString ();</p> <p>}</p> <p>}</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-29893.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="29893" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.051</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'kmeLToEbVa_2FtICpoTv671eM5OuHqoKsCVut_2BS62BSnJpZXJ9_2F5q0ePtM_2FMyeED9Q1glG3BWD_2BCKt6XSKkj8LdA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>