Web application Development Configuration (Eclipse + Tomcat + webwork + Hibernate)

Source: Internet
Author: User
Tags constant tomcat
1. Required Software

1. JDK 1.4.2 or later

2. Eclipse 3.1.2

3. Tomcat's Eclipse platform plugin com.sysdeo.eclipse.tomcat_3.0.0

4. Tomcat version 5.5.16

5. Download Webwork2.2.2, http://www.opensymphony.com/webwork/ 2. JDK installation

Execute the J2SDK Setup program, and then install it by default.

After installing the J2SDK, you need to configure the environment variables and add the following environment variables to the system variables, such as environment variables, properties, such as My computer (assuming your j2sdk is installed in c:/j2sdk1.5.0):
  
java_home=c:/j2sdk1.5.0
Classpath=.; %java_home%/lib/dt.jar;%java_home%/lib/tools.jar; (.; Must not be less because it represents the current path)
Path=%java_home%/bin
  
You can then write a simple Java program to test whether the J2SDK has been successfully installed:
  
public class test{
public static void Main (String args[]) {
System.out.println ("This was a test program.");
}
}
  
Save the above program as a file named Test.java.
  
Then open a command Prompt window, CD to your Test.java directory, and type the following command
  
Javac Test.java
Java Test
  
At this point if you see the print out this is a test
Program. The installation is successful, if you do not print out this sentence, you need to carefully check your configuration situation. 3. Eclipse 3.1.2 Installation

Unzip the downloaded Eclipse 3.1.2, such as unzip to d:/, then D:/eclipse will be the installation path for Eclipse.

By default, the Eclipse platform uses the default JRE. If you need to change the JRE at eclipse startup, you can choose Window > Preferencesto open the Preferences dialog, as shown in the following figure.

Select the Java option in the tree view on the left. Expand the Java element and select the installed JRE, as shown in the following figure.



This completes the installation of the Eclipse SDK. 4. Sysdeo plug-in installation

Extract the Sysdeo plugin directly to the plugins directory in the directory where eclipse resides. For example, the directory where eclipse resides is D:/eclipse, then extract the Sysdeo plugin into the D:/eclipse/plugins directory.

To restart the Eclipse platform, we will see the Tomcat icon displayed in the toolbar. 5. Tomcat Installation

Execute the Setup program for J2SDK and Tomcat, and then install it by default.

After installing Tomcat, add the following environment variable (assuming your Tomcat is installed in C:/tomcat) to the system variable, advanced environment variable, properties, such as My computer:
  
Catalina_home=c:/tomcat
Catalina_base=c:/tomcat
  
Then modify the environment variables in the CLASSPATH, the Tomat installation directory under the Common/lib (can be appended according to the actual) Servlet.jar appended to the CLASSPATH, the modified classpath as follows:
  
Classpath=.; %java_home%/lib/dt.jar;%java_home%/lib/tools.jar;%catalina_home%/common/lib/servlet.jar;
  
You can then start Tomcat, Access http://localhost:8080 in IE, and if you see the Tomcat Welcome page, the installation is successful.

The next step is to set up Tomcat's preference on the eclipse platform.

Set up Tomcat home, as shown below:

Set up Tomcat base, as shown below:

6. WebWork 2.2.2 Installation,

1. Create a Tomcat Project with the following directory structure:



2. Unzip the WebWork package and copy some core packages from the Webwork-2.2.2.jar and Lib directories to the Web-inf/lib directory of the Web application with the following deployment structure:



3. Create the configuration file Web. xml and Xwork.xml. The Web. xml file is located in the Web-inf directory, Xwork.xml is located in the Web_inf/src directory. The schematic is as follows:



This allows for the deployment of WebWork to 7. HelloWorld Example:

1. Edit the configuration file Web. xml

In the Web. xml file, configure a dispatcher servletdispatcher, which initializes some configuration information for the Webwrok, parses the Xwork action configuration information, assembles and invokes the corresponding interceptor (interceptor) according to the request, Action, action result (the output of the action execution result), and so on, are configured as follows:

<?xml version= "1.0" encoding= "UTF-8"?>

<! DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.3//en"

"Http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>

<servlet>

<servlet-name>webwork</servlet-name>

<servlet-class>

Com.opensymphony.webwork.dispatcher.ServletDispatcher

</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>webwork</servlet-name>

<url-pattern>*.action</url-pattern>

</servlet-mapping>

<taglib>

<taglib-uri>webwork</taglib-uri>

<taglib-location>/WEB-INF/lib/webwork-2.2.2.jar</taglib-location>

</taglib>

</web-app>

2.       creates the package Com.example.hello in Web-inf/src, and then creates the Helloworldaction class in the package. Helloworldaction is an ordinary Java class that implements the action interface. The action is a very simple interface with only one method: Public String Execute () throws Exception; Helloworldaction has a String type field greeting, in the Execute () method, greeting is assigned the value "Hello world!" and returns a string constant success, The definition of success is described in the action interface, which represents the successful execution of the Execute () method and returns the Success page.

Package Com.example.hello;

Import com.opensymphony.xwork.Action;

public class Helloworldaction implements action{

String greeting;

Public String getgreeting () {

return greeting;

}

Public String Execute () throws Exception {

Greeting = "Hello world!";

return SUCCESS;

}

}

3. Create a return page greeting.jsp. Greetings.jsp is a very simple JSP page that uses WebWork's own tag library. Its function is to output the value of the variable "greeting". This <ww:property value= the "greeting"/> statement, which is equivalent to invoking the Helloworldaction () method of the corresponding action (getgreeting) to obtain the value of the variable "greeting".

<%@ taglib prefix= "ww" uri= "WebWork"%>

<title>first WebWork example</title>

<body>

<p><ww:property value= "Greeting"/></p>

</body>

4. Add a profile for action and view connections in Xwork.xml

The Xwork.xml file structure is as follows:

<?xml version= "1.0" encoding= "UTF-8"?>

<! DOCTYPE xwork Public "-//opensymphony group//xwork 1.0//en"

"Http://www.opensymphony.com/xwork/xwork-1.0.dtd" >

<xwork>

<include file= "Webwork-default.xml"/>

<package name= "Default" extends= "Webwork-default"

Namespace= "/example" >

<action name= "Hello"

class= "Com.example.hello.HelloWorldAction" >

<result name= "Success" type= "Dispatcher" >

<param name= "Location" >/greeting.jsp</param>

</result>

</action>

</package>

</xwork>

Package tag: namespace= "Example", which means calling the action namespace; action tag: name= "Hello", which indicates that the identity calling this action is Hello, This action can be accessed via the following URL: .../example/hello.action,
For example: http://localhost:8080/helloworld/example/hello.action;class= "Com.example.hello.HelloWorldAction" is well understood, This is the class that really calls execution.

Result tag: name= "Success", remember the previous helloworldaction return character constant success it. Its value is actually "</

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.