Add struts, hibernate, and spring Support (Eclipse) __web for Web Engineering

Source: Internet
Author: User
Tags tld

Author original, reproduced please specify the source, thank you.

Add struts and hibernate support (Eclipse) for Web engineering

One: Add struts support:

1: Build your own Web project.

2: Add struts support to the Web app, and first copy the jar files from the Lib directory under struts to the Web-inf/lib directory of the Web App.

3: If you need to use the tag library of struts, you should copy all the TLD files in the Lib directory to the Web-inf directory of the Web application, and if you are using the servlet2.4 previous specification, configure the tag library to be used in the. xml file, as follows:

<jsp-config>

<taglib>

<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-html.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

</taglib>

</jsp-config>

If you are using a servlet2.4 specification, you will no longer have to configure it in the Web. xml file.

By completing these configurations, you can specify the location of the label in the JSP page where you want to use the struts tag, as follows:

<%@ taglib uri= "/web-inf/struts-bean.tld" prefix= "Bean"%>

<%@ taglib uri= "/web-inf/struts-logic.tld" prefix= "logic"%>

<%@ taglib uri= "/web-inf/struts-html.tld" prefix= "html"%>

Or is:

<%@ taglib uri= "Http://struts.apache.org/tags-bean" prefix= "Bean"%>

<%@ taglib uri= "http://struts.apache.org/tags-html" prefix= "html"%>

<%@ taglib uri= "http://struts.apache.org/tags-logic" prefix= "logic"%>

The effect of these two formulations is the same.

However, this is a complex approach, and each time you want to use these 3 tags, you need to declare them in a file. It is easier to create a taglibs.jsp file, put the label's declaration in this file, and then each time you want to use the struts tag, just put this file included in the Taglibs file content:

<%@ taglib uri= "Http://struts.apache.org/tags-bean" prefix= "Bean"%>

<%@ taglib uri= "http://struts.apache.org/tags-html" prefix= "html"%>

<%@ taglib uri= "http://struts.apache.org/tags-logic" prefix= "logic"%>

In the file using the struts tag: <% @include file= "taglibs.jsp '%>

4: If you want to use struts for data validation, The Validator-rules.xml (this file is generic, no user editing) files should be copied to the Web-inf path of the Web application, and then the Validator.xml file is established under this path, specifying the scope and rules of the checksum, which is to be edited by the user. Then add the following in the Struts-config.xml file:

<plug-in classname= "Org.apache.struts.validator.ValidatorPlugIn" >

<set-property property= "pathnames" value= "/web-inf/validator-rules.xml,/web-inf/validation.xml"/>

<set-property property= "Stoponfirsterror" value= "true"/>

</plug-in>

5: If you need to use struts expressions, you should copy all the jar files under the Contrib/struts-el/lib path under the Struts directory to the Web-inf path of the Web application, and then copy the corresponding TLD files to that path. and configure the appropriate tag libraries in the Web. xml file.

6: Internationalization, create the desired properties file for internationalization, and then add the following in the Struts-config.xml configuration file:

<message-resource parameter= "message"/> where message is the file name of the internationalized file.

Two: Add hibernate support

1: Copy the Hibernate3.jar file under Hibernate to the Web app's Web-inf/lib directory and install the Hibernate tools plugin for Eclipse, as follows:

First create the Links folder under the Eclipse directory, Create a Hibernate.link file under the folder (the file name can be arbitrary, in order to differentiate, preferably using the same name as the plugin), and then create a Hibernatetools folder under the Eclipse directory, and then create a Eclpipse folder under this folder, will Hiberna Te-tools under the features and plugins two folders copied to this folder;

Then edit the Hibernate.link file, content:

Path of the Path=hibernatetooos

It is best to use absolute paths, such as: C:/eclipse-j2ee-europa/eclipse/hibernatetools

It is important to note that the directory under the Hibernatetools folder is such that/eclipse/and then Eclipse is features and plugins two folders.

If the settings are successful, click to select the project, then select the New->other menu, and the Hibernate option will appear in the dialog box that appears.

Use Hibernate-tools to create a hibernate.cfg.xml file, configure your own database connection, and then establish your own mapping file for each persisted class, indicating the location of the mapping file in Hibernate.cfg.xml after the mapping file configuration is complete.

Three: Add spring support

1: Download the Spring-framework-2.0-dependencies.zip package, unzip the package, and then copy the Spring.jar package under the Dist directory to the Web-inf/lib directory of the Web App.

2: Copy the jar file under the Cglib, dom4j, jakara-commmons, log4j folder under the Lib path to the Web-inf/lib directory of the Web App.

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.