Configure your development environment
Note: This chapter is only related to your own application with echo. If you only intend to use a guidelines that have not been modified, you only need to read the previous chapter "Establishing Sample Program" is enough.
To install Echo, you need a Java Servlet Container that complies with the Java Servlet 2.2 specification. If you haven't yet, we recommend you use the open source Free Software Jakarta Tomcat Servlet Container 4.0 and above. You can download it from jakarta.apache.org. Any J2EE 1.2 application server will provide Java Servlet 2.2 Container.
Create an application
If you want to build your own app, you first need to download the latest stable version of Echo. Unzip the Zip (or Tar.gz) package, put the echo.jar and echoserver.jar in the lib / subdirectory. These two files must be available to Java virtual machines when you compile and run the Echo program.
If you want to pack your program into a web package:
Copy the echo.jar and echoserver.jar files to your project's web-inf / lib directory.
If you are not:
Determine the echo.jar and echoserver.jar files available under the classpath of your program runtime environment.
Distribute and use echo.jar and echoserver.jar in your program are allowed. (Including business procedures and non-open source)
Hello, World!
The first Echo sample program will be built on all the actual purposes in the browser in the browser to display "Hello, World!" To display "Hello, World!" On the browser. The easiest Echo application. The screen below shows a very common output of the Hello World program.
Example Browser Session of The Hello, World! Example.
If you have already installed the Echo Guide sample program, you can visit
Http: // localhost: 8080 / eChotutorial / HelloWorld to run this example. If your server is not running on the 8080 port of localhost, you must remember to modify the HostName and the port number.
All ECHO programs will minimize two classes. The first, you must inherit the EchoServer class of Echo to create a "user instance" that allows each user access to the Echo application. The second class is the application own user instance, which must inherit the EchoInStance class of the Echo.
Hello World only contains two classes that must be. The first is the HelloWorldServlet inherited from echoserver. EchoServer only provides users with a newInstance () method, the purpose of the newInstance () method is to create a unique user instance when a new user visits the Echo application. As seen in the sample program, NewInstance () is only simply returns an instance of the HelloWorld object. EchoServer inherits the Httpservlet class of Java Servlet Container without any actual meaning, it just allows the Echo program to run on all Servlet Container.
The second class of this example defines the Hello World program itself. This class called HelloWorld inherits from echoinstance. EchoinStance represents the only user instance of the ECHO program. Users are only asked to provide a way: init (). The init () method is equivalent to the Static Main (String [] ARGS) initialization method of the desktop program.
The init () method must return an Echo Window object. The Window object represents the content of the user browser window. When the user accesses the ECHO program, the program will display the content in the user's open browser window. This open window will be represented by the returned Window object. HelloWorldServlet.java
Import nextApp.echo.contentpane;
Import nextapp.echo.echoinstance;
Import nextapp.echo.label;
Import nextapp.echo.window;
Import nextapp.echoservlet.echoserver;
Public class helloworldservlet extends echoserver {
// Returns a new user-instance of the echo application.
Public echoinstance newinstance () {
Return new helloworld ();
}
}
Class HelloWorld Extends echoinstance {
// this init method is caled when a user first visits the
// Application. IT Must Return A Window Object That Will
// Occupy The Contents of The User's Open Browser WINDOW.
Public window init () {
// Create a new window.
Window window = new window ();
// Create a content Pane. Components May Not Be Added
// Directly to A Window, Only to a content Pane.
ContentPane Content = New ContentPane ();
// set the window's content to be the content pane.
WINDOW.SETCONTENT (Content);
// Create a new label That Says "Hello, World!"
Label label = new label ("Hello, World!");
// add the lael to the content pane.
Content.add (label);
// Return the new window.
Return window;
}
}
-
PS: I just started to translate things, I haven't forgive me.