Java Learning EE

Source: Internet
Author: User
Tags configuration settings

What is the Java EE article excerpt from other blog posts. What is the Java EE
First, prepare the article

1 What is the Java EE? How does it differ from normal Java?
A: The EE is all called Java2 Platform Enterprise Edition.
"The EE platform is essentially a distributed server application design environment-a Java environment that provides:
• A running infrastructure environment for the host application.
• A set of Java extension APIs to create apps. (from "Java EE server-side advanced programming")

2 is the Java EE studious?
A: The Java EE is a collection of many technologies and is still growing.
You will encounter many proper nouns: for example (X) Html,servlet/jsp,jdbc,jms,jndi,ejb,xml,web Service ....
In particular, XML and Web service are growing fast. Fortunately, you don't have to wait until you have learned all the techniques before you start programming.
In general, the Java EE can be divided into 3 main applications: Servlet/jsp,ejb,xml/web Service and some support technologies such as JDBC and Jndi.
You can learn by one.

What is the Java EE. Why you need a Java EE.
3 What's the use of EE?
A: Java EE is used to build large, distributed enterprise-class applications. Or, in a more fashionable term, "e-commerce" applications.
These enterprises may be large to have a central database server, Web server clusters and office terminals all over the country, it may be small to just want to do a website.

4 Is there a future for EE?
A: There is currently only one technology in this market that can compete with the Java EE, which is Microsoft's. NET.
Relatively speaking. NET to "new" some and the "old" of the EE.
But. NET can only be used on Windows platforms (Microsoft claims to be developing C # virtual machines on Linux but has not yet fulfilled that promise),
Take into account the development of Linux, you can believe. NET does not eminence.

5 It is said that the performance of the Java EE is not as good as. NET, is it true?
A: On the sample program provided by Sun Company, Microsoft claims that it is not as good as the same. NET program on the pet store.
Sun countered that the program did not really reflect the performance of the Java EE and accused Microsoft of optimizing the database.
The author has not studied. NET thus cannot presume to assert.
In any case, performance bottlenecks in large distributed programs are often the first to come from the wrong design.

6 Listen to you say so much, I want to learn to play with the Java EE.
A: Don't waste your time unless you want to eat it or use it as a technical reserve.
Flash is much better to play. Computer games are much more fun.

7 Learn how to start the Java EE?
Answer: First, download a Java EE server. Second, go to java.sun.com to download the Java EE API. Third, find a good reference book. Finally, find a handy IDE.
Java EE server. You can use Sun's Java EE SDK (free), or WebLogic (the best performance, but too big, and the author does not recommend piracy), or JBoss (free, is too few documents), or JRun (developer free, the author uses this). Reference authors feel Wrox's "Java EE server-side advanced programming" is good, but too old (the author is in the 2001 Chinese version). You also need to download some of the latest technical information (certainly in English).
IDE If your machine is well configured (memory at least 512M or less, do not consider it at 256M or below), you can use IBM Wsad, or continue with eclipse or other.
You can often go to the Java edition of the water-wood Tsinghua, but before you post it, see if there is any answer you want in the essence area.

8 I have a Java EE server but not configured.
A: Please read the random guidance document carefully, different server configuration is not the same, the author can not help.

9 I found you didn't mention Tomcat.
A: Tomcat is just a Web server, more accurately, mostly just a web Container.
If you want to learn about EJBS, Tomcat won't be able to meet your needs.

Second, servlet/jsp article

10 What is a servlet?
A: A servlet is a Java class. It handles HTTP (s) requests and responds, including returning an HTML page or handing over to other URL processing.
The servlet must be running 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, which corresponds to the GET request and the POST request in HTTP (s) respectively.

11 How do I get the parameters in the HTTP request?
Answer: HttpRequest's GetParameter () method. Example: String paramvalue = Request.getparameter ("paramname");

12 How do I return results?
A: You can use the relevant API to open an output stream and write an HTML page directly to the stream.
But the author is totally against it. On the one hand this will be very wordy.
On the other hand, from the point of view of Model-view-controller mode (which is classified as the front controller mode in the "Java EE Core model"),
You should provide some HTML or JSP as a view, and the servlet will decide which view to go to according to the request parameters.
You can use Response.sendredirect (...) method or Request.getdispatcher (...). Forward () method to implement.

What is the difference between sendredirect () and forward ()?
A: Sendredirect () is sending a redirect notification to the browser, and the browser redirects to the new URL.
The forward is directly to the new URL on the server side and is transparent to the browser.
The former browser's address bar displays a new URL, and the browser's address bar shows the URL of the servlet.
As a result, when the destination URL is automatically refreshed, there are some differences between the two.

14 I wrote a servlet program, how to run it?
A: The development of the Java EE program has a concept of deployment (deploy), which is actually the trilogy of development-deployment-operation.
Most servers support hot deploy. You only need to be under the corresponding application directory (the specific path depends on the server)
Create a directory that matches the war or ear format (see 16,17) and launch the server, which you can access through the browser.
In particular, your servlet's class file should be placed in the/web-inf/classes directory.
Note the Java EE SDK does not support hot deploy, and you need to deploy it through its deploy tool.
Tomcat only supports the war format.

What is the difference between the ear and the war?
A: The ear is a complete Java EE application, including the Web section and the EJB section.
The war is just one of the Web Parts.

What is the format of the ear?
A: An ear can contain any number of war or EJB jars, and contains a meta-inf directory.
A application.xml is included in the/meta-inf that describes which modules the ear contains and the security configuration.
Please see reference books for details.

What is the war format?
A: A war contains a Web-inf directory, which contains the classes directory, the Lib directory, and Web. Xml.
/web-inf/classes store the class file organized by the package, the/web-inf/lib directory holds the jar file,
Web. XML describes a lot of things, please read reference books.

18 Where should my normal HTML files be placed?
Answer: Put in a place other than/web-inf.

19 I don't have access to Servlets, even HTML files!
A: First you did not start the server. Second you knocked the wrong port. Third you did not correctly configure the Context-path.
IV Your server does not support auto reload or if you turn off this option, you have to restart the server.
Confirm that you did not put HTML in the/web-inf directory, which is not accessible.

20 I can access HTML but I can't access the servlet.
Answer: Please check your Web. xml file. Make sure you define the <servlet> and <servlet-mapping> elements correctly.
The former identifies a servlet, which maps a URL relative to Context-path to a servlet.
In Tomcat you can access the servlet in the form of/context-path/servlet/package/servletname,
But this is just a handy way to access Tomcat, not a formal norm.
Please see reference books for details.

21 What is a JSP? What is the difference between it and the servlet?
A: You can treat JSPs as an extensible HTML.
Although in essence, the JSP file will be automatically translated by the server to the corresponding servlet to execute.
It can be said that the servlet is for Java programmers and JSP is for the HTML programmer, in addition to the two functions are completely equivalent.

22 My JSP displays the Chinese characters are garbled.
A: At the beginning of your JSP add a line <%@ page contenttype= "text/html; charset=gb2312 "%>
If you have already declared the page, I think you know how to modify it.

Where are the. jsp files stored?
A: Except for any place under the/web-inf.

24 How to refer to Java beans in JSP.
A: First, confirm that the class you are referencing is under/web-inf/classes or within a jar in/web-inf/lib.
Next, in the JSP add a line <jsp:usebean id= "..." scope= "..." class= "..."/>
Please refer to the reference book for specific explanations.

25 I want to pass data between Servlets.
Answer: Use session. In servlet/jsp, you can save data in 4 places.
1) page, this screen.
2) session, used to store customer-related information, such as shopping cart, the corresponding interface for javax.servlet.http.HttpSession.
The session mechanism is actually an abstraction of the cookie and URL rewrite, and the server automatically uses the cookie or URL rewrite to implement it.
3) Request, you can pass the information at forward (), the corresponding interface is javax.servlet.http.HttpRequest.
4) application, or context, store global information, corresponding interface for Javax.servlet.ServletContext.

26 How do I invoke cookies?
A: The author recommends using session, you will always encounter some users who disable cookies. The session is then automatically implemented using URL rewriting.

27 How to implement file download in JSP?
A: Actually, this is an HTML problem. The answer is a hyperlink <a>.

28 How to implement file upload?
A: The client is an HTML problem, set method in form to Post,enctype to Multi-part/form-data, plus a <input type= "file" >.
In the received servlet, it is just an I/O problem.

29 I want to make the page refresh automatically, such as chat room.
Answer: This is an HTML problem, add a <meta http-equiv= "Refresh" content= "5" > "Url=" in the This is called the Clinet-push, client refresh technology.

30 I want users to log in before they can access the page.
Answer: Use declarative security.
You only need to define a security role (role) in Web. XML and define a protected URL collection that can only be accessed by a specific role.
Most servers support database-based user mappings, as long as you create two tables in the appropriate database and configure the server.
Note the Java EE SDK does not support database-based user mappings.
See reference books and server documentation for details.

31 I want to be able to register users.
Answer: see 30. The write database operation is performed in the servlet that accepts the registration request.

32 How do I access the database in the JSP?
A: The standard practice is to use the DAO pattern, define a Java bean to access the database and use it in the JSP.
However, when your database schema is simple, you can use the <sql:query> tags in jstl for quick access.

33 What is JSTL?
Answer: JSTL is the abbreviation of JSP Standard TAG library. This is a common set of tags and will be part of JSP 2.0.
It contains assignment <c:set>, branch <c:if>, loop <c:foreach> query database <sql:query> Update Database <sql:update>
such as Currently you need to add Jstl as you would add a custom tag library, but you can expect JSP 2.0 to have Jstl as part of it.
The tag library can be downloaded in http://jakarta.apache.org. Note Jstl needs to run under a container that supports JSP1.2 or later. The Help file can read the Sun's JSTL formal specification.

How to Master Java (j2se article)?
Java itself is a very simple design, very sophisticated language, so the principle behind Java is very simple, it boils down to two points:
1, the memory management of the JVM
Understanding this, all problems related to the object can be solved.
2. JVM Class Loader
Understand this, all Java-related configuration issues, including the configuration of a variety of app servers, application publishing issues can all be resolved

Often see some people say mastered the Java, but let them use Java to do a real project may be difficult, here, the author according to their own a little understanding of the courage to come up with some of the standards of Java, of course, for beginners, but also can provide a reference to learn what content. In addition, this standard is limited to the J2SE section, the contents of the Java EE section have time to say otherwise.

1, syntax: Must be familiar, in writing code when the IDE editor on a line error should be able to according to the error message to know what kind of grammatical errors and know any corrections.
2. Command: Must be familiar with some common commands of the JDK and its common options, commands need to be familiar at least: Appletviewer, Htmlconverter, jar, Java, Javac, Javadoc, JAVAP, JAVAW, Native2ascii , Serialver, if you haven't used all of these commands, you really don't know much about Java.
3. Tools: You must be at least proficient in using an IDE's development tools, such as Eclipse, Netbeans, JBuilder, Jdeveloper, Idea, JCreator, or workshop, including project management, settings for common options, Plug-in installation configuration and debugging.
4, Api:java core API is very large, but there are some content I think must be familiar with, otherwise it is not possible to skillfully use Java, including:
1), Java.lang under the package of more than 80% of the functions of the flexible use of the class.
2), the flexible use of more than 80% classes under the Java.util package, especially the collection class system, regular expressions, zip, and time, random number, attributes, resources and timer.
3), the use of more than 60% of the class under the Java.io package, understanding the IO system based on the pipeline model design ideas and commonly used IO class characteristics and applications.
4), the content of the Java.math package under 100%.
5), java.net under the package of more than 60% of the content, the function of each class is more familiar.
6), more than 60% of the content under the Java.text package, especially the various formatting classes.
7), skilled use of JDBC.
8), java.security more than 40% of the content, if the security has no contact, it is impossible to master Java.
9), the basic content of AWT, including various component events, listeners, Layout manager, common components, printing.
10), Swing's basic content, and AWT's requirements are similar.
11), XML processing, familiar with the advantages and disadvantages of sax, Dom and Jdom and can use one of the XML parsing and content processing.
5. Test: You must be familiar with automated tests that use JUnit to write test case completion code.
6, Management: Must be familiar with the use of ant to complete project management of common tasks, such as Project compilation, build Javadoc, build jar, version control, automated testing.
7, the wrong: should be able to be based on the abnormal information to locate the cause of the problem and approximate location.
8, thinking: Must master the main requirements of OOP, so that the use of Java development system to be a real Java system.
9, Specification: The code must conform to the popular coding specifications, such as the first capital of the class name, the first letter of the member and method name lowercase, the method name is usually a verb, the package name all lowercase, etc., so that the readability of the program is better.

What is the Java EE

Java EE: The rapid development of e-commerce and information technology and the need for them put new pressure on application developers.
You must design and develop enterprise applications more quickly, with less money and less resources than ever before. To reduce costs and accelerate the design and development of enterprise applications, the Java EE platform provides a component-based approach to designing, developing, assembling, and deploying enterprise applications. The Java EE platform provides multiple layers of distributed application models, component reuse, a consistent security model, and flexible transaction control. Not only can you deliver creative customer solutions to the market faster than before, but your platform's standalone, component-based Java EE Solutions won't be tied to any one vendor's products and APIs.
1. The Java EE specification defines the following types of components
• Apply Customer components.
Enterprise JavaBeans components.
servlet and JavaServer Pages (JSP page) components (also known as Web Components).
applet.
A multi-tiered, distributed application model means that application logic is divided into components based on functionality and can be
These different components that make up the Java EE application are installed on the server or on different servers. What an application component should be installed on
Place, depending on which layer of the application component belongs to the multi-tier Java EE environment. These tiers are customer tiers, We b tiers, business
and the Enterprise Information System layer (EIS).
(1) Customer level
The Java EE app can be web-based or web-based. In a web-based Java EE application, the user's browser runs in the customer tier and downloads a static HTML page from a we-B server or a dynamic HTML page generated by J S p or servlet. In a non-web-based Java EE application, a standalone client program does not run in an HTML page, but instead runs in some other network-based system (such as a handheld device or a car phone), applets, runs in the customer tier, and does not go through the web Layer in case of access to Enterprise Beans. This non-web-based customer tier may also include a JavaBeans class to manage user input and send that input to an enterprise beans class running in the corporate tier for processing. According to the Java EE specification, the JavaBeans class is not considered a component. The JavaBeans class written for the Java EE platform has an instance variable and a "Get and set method" to access the data in the instance variable. The JavaBeans classes used in this way are usually simple to design and implement, but they must conform to the naming and design conventions listed in the JavaBeans specification.
(2) Web tier
The Java EE Web component can consist of a JSP page, a p p l e t based on the web, and a s e R v L e t that displays an HTML page. HTML pages that call S E R v L e T or JSP pages are packaged together with the Web Components when the application is assembled. Just like the customer layer, the Web tier might include a JavaBeans class to manage user input and send input to the Enterprise Beans class running in the business layer for processing. Web Components that run at the client level rely on containers to support such things as customer requests and responses, enterprise Bean queries, and so on.
(3) Business layer
The business code that is required to resolve or satisfy a particular business area (such as banking, retail, or financial) is executed by an enterprise Beans running on the business layer. An enterprise Bean receives data from the client program, processes the data (if needed), and then sends the data to the enterprise Information System layer for storage. An enterprise Beans also retrieves data from the store and sends the data back to the client program. Enterprise Beans running at the business level relies on containers to provide system-level code that is often very complex for transactions, lifetimes, state management, multithreading, and resource storage pools. The business layer is often referred to as the Enterprise JavaBeans (EJB) layer. The business layer and the Web tier form the middle tier of the 3 layer J 2 e e application, while the other two tiers are the customer tier and the enterprise Information System layer.
(4) Enterprise Information System layer
The Enterprise Information System layer runs enterprise information system software, which includes enterprise infrastructure systems such as enterprise resource planning (E R P), mainframe transaction processing (mainframe transactionprocessing), database systems, and other legacy information systems (legacy Informationsystems). The Java EE application component may require access to the enterprise information system for some reason, such as accessing the database. Future versions of the Java EE platform will support the connector architecture, a standard a P I that connects the Java EE platform to an enterprise information system.
(5) Enquiry Service
Because the components of a Java EE application are run separately and often run on different devices, you need a way to let the customer layer and the Web Layer Code query and reference other code and resources. The client layer and the Web layer code use Java naming and directory interfaces (JNDI) to query user-defined objects (such as Enterprise Beans), environment entries (such as the location of a database drive), JDBC DataSource objects used to find resources in the Enterprise Information System layer , as well as message connections.
(6) Security and transaction management
Application behaviors such as security and transaction management can be configured on the Web and enterprise Beans components at deployment time. This feature separates the application logic from the configuration settings that may vary with the assembly. The Java EE security model allows you to configure a Web or Enterprise Beans component so that system resources can only be accessed by authorized users. For example, a Web component can be configured to prompt for a user name and password. An enterprise Beans component can be configured to allow only members of a particular community to invoke some of its methods. Alternatively, a servlet component can be configured so that everyone in an organization can access some of its methods, and only some privileged people in that organization have access to some of them. Also the servlet component, which can be configured for another environment to allow everyone access to all of its methods, or just the selected few to access all of its methods.
The EE transaction model enables you to define the relationship between the methods that make up a single transaction at deployment time so that all the methods in a transaction are processed into a single unit. This is what we want because a transaction is a series of steps that either complete or cancel all. For example, an enterprise Beans may have a set of methods that allow us to transfer money from the first account to the second account by borrowing and depositing a second account from the first account. We want all operations to be treated as a unit, so that if a failure occurs before the loan is deposited, the loan operation is canceled. Transaction properties are defined on a component during assembly. This makes it possible to classify methods from multiple application components into a single transaction, which means that we can easily change the application component in a Java EE application and reassign the transaction properties without having to change the code or recompile. When designing an application component, keep in mind that although Enterprise Beans has a mechanism that enables the container for application components to automatically start a multi-step transaction, the applet and the client container for the app may not support this. However, applets and application client containers are always able to invoke an enterprise Beans that supports this point. It should also be noted that JSP pages and Servlets are not designed to be transactional, and they should usually be done by handing the transaction work to an enterprise Bean. However, if transactional work is required in a JSP page or servlet, such work should also be very limited.
(7) Reusable application components
The Java EE components (applets, application customers, Enterprise Beans, JSP pages, and Servlets) are packaged into modules and delivered as a Archive (JAR) file. A module consists of related components, related files, and configuration profiles that describe how to configure a component. For example, during assembly, an HTML page and servlet are packaged into a module that contains an H T M l file, a Servlet component, and a related configuration profile, delivered as a web Archive (war) file that is a band. War The standard jar file with the extension. The use of modules makes it possible to assemble different Java EE applications using some components from the same component. For example, the web version of a Java EE application might have an enterprise Beans component and a JSP page component. The Enterprise Beans component can be combined with an app customer component to generate a non-web version of the application. This does not require additional coding, just an assembly and deployment issue. Also, reusable components make it possible to divide the application development and deployment process into different roles, so that different people or companies can complete different parts of the encapsulation and deployment process.
2. The Java EE platform defines the following roles:
(1) Java EE product provider
Companies that design and enable the Java EE platform, API, and other features defined in the Java EE specification to be acquired by other companies or people.
(2) Application Component Provider
A company or individual that creates Web Components, Enterprise Beans components, applets, or application clients for a Java EE application. The application component files, interfaces, and classes are packaged into a jar file during assembly.
(3) Application assembler
The company or individual that obtains the application component jar files from the component provider and assembles them into an enterprise Archive (E a R) file for a Java EE application is a band. The standard file for the E a r extension. The application assembler provides the overall information associated with the application and uses the validation tool to verify that the contents of the ear file are correct. The Assembly and deployment information is stored in a text-based configuration profile that uses XML tags to mark the text. An application assembler can edit the configuration profile by using an assembly and configuration tool that can correctly add XML tags through interactive selection.
(4) Deployment Provider
Deploy (d e p l e y) the company or individual of the Java EE application. Its responsibilities include setting transaction control, security attributes, and indicating whether an enterprise Bean handles itself or is handled by a container, depending on the instructions provided by the application component provider. Deployment involves configuration and installation. During the configuration process, the deployer follows the instructions provided by the application component provider to resolve external dependency issues, define security settings, and assign transaction properties. During the installation process, the Deployer installs the application components on the server and generates container-specific classes and interfaces.
(5) System administrator
Configure and manage the computing environment and network infrastructure that runs the Java EE application and oversee the people running the environment.
(6) Tool providers
A company or individual that manufactures tools used by component providers, assemblers, and deployer for development, assembly, and packaging.
(7) Design user interface and engine
When designing the user interface and backend engine for the Java EE application, it is necessary to decide whether the program is based on we B, or not based on we B. In making this decision, we may want to consider platform configuration, download speed, security, network traffic, and network services.
For example, an applet that contains a user interface and is often accessed by a large number of users can take a long time to be downloaded, frustrating for the user. However, if you know that the A P p l e T is to run in a controlled environment within a company's intranet, in this case the applet will have a fully acceptable download speed. Another consideration is where the heavy processing should be carried out. For example, if a client program is executed in a cellular phone or pager, the server should do as much computation and data processing as possible, and the client program should only display the results. However, a large financial analysis system designed to run on a powerful desktop platform should perform its complex calculations on the client. The application's client program and a P p l e T user interface are usually created with the swing API, which is available from the standard version of the J a V a 2 platform. The Swing API provides a complete set of GUI components (tables, trees, buttons, and so on) that can be used to implement a more interactive experience than a typical HTML page can achieve. Swing also supports HTML text components, which can be used to display responses from a single server. The client program can access the enterprise Beans layer or the Business Information system layer directly. However, such procedures should be implemented with caution.
Programs that bypass the EJB layer can use the JDBC API to access a relational database, but should be limited to administrative tasks such as maintaining database tables.
Read more J2EE,JAVA,EJB related articles:

Java Learning EE

Related Article

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.