First, prepare 1 What is J2EE? What is the difference between it and ordinary Java? A: J2EE is all called Java2 Platform, Enterprise Edition. "J2EE platform is essentially a distributed server application design environment - a Java environment, which provides: • A Basic Framework Environment for host applications. · A Java extended API for creating applications." "J2EE Server Advanced Programming") 2 J2EE So good? A: J2EE is a collection of technologies and is still growing. You will encounter a lot of special nouns: such as (x) HTML, Servlet / JSP, JDBC, JMS, JNDI, EJB, XML, Web Service .... Especially XML and Web Service are growing rapidly. Fortunately, you don't need to wait until all techniques will start programming again. General J2EE can be divided into three main applications: servlet / JSP, EJB, XML / Web Service, and some support technologies such as JDBC and JNDI. You can learn one by one.
What is the use of J2EE? A: It is used to build a large distributed enterprise application. Or use more trendy nouns to be an "e-commerce" application. These companies may be large to have a central database server, a web server cluster, and a national office terminal, or it may be small to just want to be a website.
Is there a future in J2EE? A: There is only one technology in this market to compete with J2EE, that is, Microsoft's .NET. Relatively. Net wants "new" and J2EE wants to "old". However, .NET can only be used for Windows platform (Microsoft claims to develop C # in Linux virtual machine but has not yet fulfilled this promise), considering Linux's development momentum, you can believe that .NET will not be a world.
5 It is said that J2EE's performance is not as good as .NET, is it true? A: On the sample program Pet Store, available in Sun, Microsoft claims to be better than the same .NET program. The Sun is refuted that this program cannot really reflect the performance of J2EE, and accuses Microsoft has optimized on the database. The author did not learn. Net should not agree. In any case, the performance bottleneck in large-scale distributed procedures is usually from the wrong design.
6 Listen to you, I want to learn to play. A: Do not waste your time unless you want to eat as a technical reserve, please don't waste your time. Flash is much more fun. Computer games are more fun.
7 How to start learning J2EE? A: First, download a J2EE server. Second, go to java.sun.com to download J2EE's API. Third, find a good reference book. Finally, find a handful IDE. J2EE server. You can use Sun's J2EE SDK (free), or WebLogic, but too big, and the author does not recommend piracy behavior), or JBoss (free, it is a document), or JRUN (development version free, This one). The reference author feels that Wrox's "J2EE server-side advanced programming" is good, but it is too old (the author's hand is the 2001 Chinese version). You still need to download some of the latest technical information (of course, is definitely English). Ide If your machine is equipped enough (at least 512M or more, do not consider 256M or less), you can use IBM's WSAD, or other. You can also go to Shuimu Qinghua Java version, but before you post, you can see if there is any answer you want in the essence. 8 I got a J2EE server but won't configure it. A: Please read the random guidance document carefully. Different server configurations are different, the author loves.
I found that you didn't mention Tomcat. A: Tomcat is just a web server, more accurately, is just a Web Container. If you want to learn EJB, Tomcat can't satisfy your needs.
Second, servlet / jsp
10 What is servlet? A: A servlet is a Java class. It processes HTTP (s) requests and responds, including returns an HTML page or transferred to other URL processing. The servlet must run in a web container such as Tomcat. The servlet must be a subclass of javax.servlet.http.httpservlet, you can inherit the Doget () or dopost () method, both corresponding to the GET request and POST request in HTTP (S).
11 How do I get the parameters in the HTTP request? A: HTTPRequest's getParameter () method. For example: String paramvalue = Request.getParameter ("paramname");
12 How do I return the result? A: You can use the relevant API to open an output stream and write it directly to the stream to a HTML page. But the author does not agree with this. On the one hand, it will be very ridiculous. On the other hand, from the viewpoint of MODEL-View-Controller mode (in "J2EE core mode", you should provide some HTML or JSP as a view (view), and servlet determines according to the request parameter One of the views to go to. You can use the response.sendredirect (...) method or request.getdispatcher (...). Forward () method.
13 SendRedirect () and forward () are there? A: sendRedirect () is to send a Redirect notification to the browser, and the browser redirects to the new URL. Forward is directly transferred to a new URL on the server side, which is transparent to the browser. The address bar of the former browser displays the new URL, the address bar of the latter browser displays the servlet's URL. Therefore, when the target URL is automatically refreshed, the two will cause some difference. 14 I wrote a servlet program, how to run it? A: Development J2EE program has a deployment concept, which is actually developing - deployment - running trilurate. Most servers support HOT Deploy. You only need to create a directory that complies with the WAR or EAR format (see 16, 17) below in the corresponding Application Directory (specific path dependencies), start the server, you can access it through the browser. Special, your servlet's class file should be placed in the / web-inf / class of. Note J2EE SDK does not support HOT Deploy, you need to deploy it through its deploy Tool. Tomcat only supports WAR format.
What is the difference between EAR and WAR? A: EAR is a complete J2EE application, including the Web section and the EJB section. WAR is just in the web section.
What is the 16 EAR format? A: An EAR can contain any multiple WAR or EJB JAR and include a directory of meta-infers. An application.xml is included in / meta-infers, which describes which modules are included, as well as security configurations. Please see the reference book.
What is the 14 WAR format? A: A WAR contains a header directory, which contains the CLASSES directory, lib directory, and Web.xml. / Web-INF / CLASSES Store the Class file of the Package organization, / web-inf / lib directory stores the JAR file, and Web.xml describes a lot of things, please read the reference book.
18 Where should I put it in my ordinary HTML file? A: Place elsewhere except / Web-INF.
19 I can't access servlet, even HTML files can't access! A: The first you didn't start the server. Second, you're pulling the wrong port. Third, you didn't configure context-pat. Fourth Your server does not support Auto Reload or you have closed this option, you have to restart the server. The fifth is confirmed that you didn't put HTML in / web-infers, it was not accessible.
20 I can access HTML but I don't access the servlet. A: Please check your web.xml file. Make sure you correctly define
21 What is JSP? What is the difference between it and servlet? A: You can treat JSP as an expandable HTML. Although the JSP file in essence is automatically translated into the corresponding servlet. It can be said that servlet is a Java programmer and JSP is an HTML programmer, in addition to this, both of which are completely equivalent.
22 The Chinese characters displayed in my JSP are garbled. A: At the beginning of your JSP, add a line <% @ page contenttype = "text / html; charset = GB2312"%> If you have declared Page I think you know how to modify it. 23 Where is the JSP file stored? A: In addition to any place under Web-INF. 24 How to refer to Java Bean in JSP. A: First, confirm that the classes you want to reference under / web-inf / classes or in a JAR in / web-inf / lib. Second, in JSP plug-in
25 I want to pass data between servlets. A: Use the session. In Servlet / JSP, you can save data in 4 places. 1) Page, this page. 2) Session, used to store customer-related information, such as shopping cart, corresponding interface is javax.servlet.http.httpsession. The Session mechanism is actually an abstraction of cookie and URL Rewrite, and the server will automatically use the cookie or URL Rewrite. 3) Request, you can transfer information at forward (), and the corresponding interface is javax.servlet.http.httpRequest. 4) Application, or CONTEXT, store global information, the corresponding interface is javax.servlet.servletContext.
26 How to call cookies? A: The author is recommended to use Session, you will always encounter some users who disable cookie. At this time, SESSION will automatically use the URL rewriting to implement.
27 How to implement file download in JSP? A: In fact, this is an HTML problem. The answer is a hyperlink .
28 How to implement a file upload? A: The client is an HTML problem. Setting Method in Form for POST, ENCTYPE is Multi-Part / Form-Data, plus one . And in the received servlet is just an I / O problem.
29 I want to let the page automatically refreshed, such as chat room. A: This is an HTML problem, plus one
30 I want to let the user can log in to access the page. A: Use declarative security measures. You only need to define security roles (Role) in Web.xml, and define protected URL gathers can only be accessed by specific role. Most servers support the database-based user mapping, you can use both tables in the corresponding database and configure the server. Note J2EE SDK does not support database-based user mapping. Please see the reference book and server documentation.
31 I want to register the user. A: See 30. Write a database operation in the servlet that is accepted registered request.
32 How to access the database in JSP? A: The standard practice is to use the DAO mode to define a Java Bean to access the database and use it in JSP. However, when your database mode is simple, you can use the