Hibernate Development Guide Environment Preparation

zhaozj2021-02-12  133

Foreword

Hibernate is a very good and has been used in large quantities of database persistence tools that have become more mature. This article is mainly for developers using Hibernate. This chapter is mainly to illustrate the initial settings of the development environment used in the Hibernate Development Guide and use a simple example to illustrate Hibernate.

The tools mainly used herein are:

JDK: JDK 1.4.2 Development Environment: Eclipse 2.1.2 Hibernate 2.1 Database: Oracle 9i Hibernate's Eclipse plugin: Tanghan Plugin Please take a look at whether you have installed these software on your machine, for the database, just because of my machine Oracle has been installed, using other databases will not have much difference. My example also uses a Struts framework, because I think Struts in the web application framework is a very good choice, and the Hibernate is accessed, and the two matches better results. In order to use Struts, please confirm that you have the following software installed:

Web Application Server: Tomcat 4.x Struts 1.1 Pack Eclipse J2EE Integrated Plug-in: MyECLIPSE 2.7RC1 or above (2.7 Starting Struts Support) If you don't want to use myEClipse, you can use Lomboz and Easystruts to replace its Features. The specific software installation and plug-in installation is not here. Let's talk about the configuration after installing.

Software configuration

Let's first configure the database, and write down the relevant information required for database development.

Oracle related configuration parameters

I created a separate user in Oracle: HD, set its password to: ABC. Assign the corresponding database space for the user, the detailed configuration method and information are no longer said, in short, you need to get the following information for development:

Machine Address: HDIBM (Because of the local machine can also use localhost and 127.0.0.1, if another machine uses the IP address of the machine) Oracle's listening port: 1521 Database instance name: HDORC Access User Name: HD Access Password: ABC needs to be aware that the role of the HD user is assigned at least Connect. In addition, it is assigned enough or unlimited limits in the table space he use, otherwise it will encounter problems during development. In addition to these, you need to download the latest JDBC package from the installed Oracle or Oracle website. It has two packages, one of which is driven with JDK, the other is multilingual support package (here we don't use OCI Drive, drive using Thin). Because I used JDK for 1.4, I used the driver package.

The multilingual support package used by OJDBC14.JAR and JDK1.4 is the same as JDK1.2.

NLS_CHARSET12.JAR.

In the database, we build some tables for program development, take a simple user management as an example, we first create a simple user table (Sysuser):

Table Name: Sysuser User ID: UserId (Vchar: 32) User Name: UserName (Vchar: 20) User Password: UserPasword (Vchar: 20) User Last Listing: LastLogin (Date) You can also use this SQL statement to create a table :

Create Table "HD". "Sysuser" ("Userid" VARCHAR2 (32) Not Null, "UserName" varchar2 (20) Not Null, "UserPasword" VARCHAR2 (20) Not Null, "LastLogin" Date, Primary Key ("UserID" "), Unique (" UserName ")) TABLESPACE" Users "Tomcat Installation

Tomcat installation is very simple, download the related installation package from the Tomcat website, you can solve the relevant directory. After installing Tomcat, you need to write down the following information:

Tomcat installation directory Tomcat's listening port (default is 8080)

Configuring Hibernate for Eclipse plugin TANGHAN PLUGIN

There will be many people without starting with this plugin, mainly, I don't know where to use this plugin. The first two views provided by this plugin: Database Access View and Database Data View. Select these two views through windows> Display View> Others on the menu:

Open the Database Access View view, let's configure Oracle drivers, with mouse right-click Oracle Thin Driver> Modify Driver Information:

Here:

Drive Name: Oracle Thin Driver Driver Package: Browse Choose Your Ojdbc14.jar File Driver Class: Oracle.jdbc.driver.OracleDriver Driver Prefix: JDBC: Oracle: Thin: @ // < Server> [: <1521>] / (here is the latest driver URL writing method, the specific best-related Oracle driver) Configuring the URL of the URL) Configure the driver we will add a database connection:

Here:

Database connection name: HDTestDB Drive Name: Oracle Thin Driver (is the above we are built) driver class: Oracle.jdbc.driver.OracleDriver database connection: JDBC: Oracle: Thin: HD @ Abc // HDIBM: 1521 / HDORC users Name: HD Password: ABC Next We tried to connect to the database:

Need to choose SHEMAS, select HD from the drop-down list, press the OK button. If you can see the choice of the SHEMAS dialog, you have no problem with your database configuration. We can see the tables and table structures in the library in Database Access View:

Configure myECLIPSE

Download from MyEclipse's website to the latest MyEclipse trial and Struts-related TLD and LIB packages. After installing myECLIPSE, configure Tomcat. It is mainly to configure the related path of Tomcat:

It should be noted that Tomcat must use a JDK instead of JRE, you can choose a JDK in Tomcat's configuration tree for Tomcat startup:

Next, the Struts packet solution downloaded from the website is disconnected into the file system (you can also remove the lib and TLD in the Struts 1.1 package), configure the Struts 1.1 related package in MyECLIPSE: These configurations are available Establish a simple project.

Establish initial Struts project

We first build a project, prepare for subsequent in-depth development, this project is a simple framework, import Tomcat deployment support, establish a library path with struts and hibernate.

Establish web application project

First use the wizard to create a web module provject:

Enter information about Web Project:

Enter one by one shown in the figure. Click to complete the establishment Project.

Join the Tomcat deployment support for the project

Next, join the Tomcat deployment support for the project:

In the pop-up dialog, point add and select Tomcat 4 in the drop-down box:

Join Struts Support for web applications

Join the project to join the Struts Support:

In the pop-up dialog box, press the image to enter information:

This joins the Struts support for the web application project, which automatically adds the TLD file (tag lib document) for the project to join the Struts support package and Struts. After that, we can see:

Join Hibernate support for web applications

There is a lot of JAR in Hibernate. It is not recommended to join all. The following is the JAR package you have to join (these package hibernate2.jar is in the lib subdirectory in the root:

Hibernate2.jar: Hibernate's core library. CGLIB2.jar: Hibernate is used to implement the library required for the dynamic generation of the PO bytecode. Commons-Collections.jar: Apache Commons provides a stronger collection class than java.util. *. Commons-lang.jar: Apache Commons provides the ability to extend java.lang. *. Commons-logging.jar: A universal log interface tool provided by Apache Commons. It uses log4j, JDK's java.util.logging, the order of Commons-logging SIMPLE Logger to find available Log APIs. Dom4j.jar: An access to XML interface implementation, Hibernate uses this package to complete the XML operation. Odmg.jar: ODMG is an ORM specification, Hibernate uses this package to implement ODMG specification. Xalan.jar, Xerces.jar and XML-Apis.jar: XSLT processors, SAX resolution, standard JAXP API packages are processed for XML. (Most application servers bring these three packages) The following packages can be added as options based on the situation in your application, by yourself:

C3p0.jar: The package used by the C3PO database connection pool. Commons-dbcp.jar and Commons-pool.jar: Apache Commons The package used by DBCP connection pool is available. JBoss-cache.jar, Concurrent.jar, JBoss-Common.jar, JBoss-JMX.jar, JBoss-System.jar: Treecache, which implements a clustered cache. Connector.jar: Standard JCA API package. Most application servers have belong. (*) EHCACHE.JAR: EHCACHE CACHE Pack, Hibernate uses this package to complete the Cache function. Jaas.jar: Standard JaaS API package. Most application servers also have this package, this package is used for JCA. (JDK 1.4 also already contains this package) JCS.jar: JCS Cache package. JDBC2_0-stdext.jar: Standard JDBC 2.0 API extension. Most application servers also contain this package. Swarmcache.jar and jgroups.jar: Swarmcache can be copied to the package used by the distributed cache. It uses JavaGroups to group communication, which is suitable for database applications for cluster environments. (*) JTA.jar: Standard JTA API package. Most application servers also have this package. Log4j.jar: log4 pack, log4j is a very good choice in the Logger tool. Oscache.jar: The OSCache package provided by OpenSymphony for the database of cache. Proxool.jar: Proxool JDBC Database Connection Pack. There are also some other packages, not the bag used in the run, attached here to learn: Ant.jar: Compiling the ANT core package used when Hibernat. JUnit.jar: JUnit Test Frame Pack, compile time to test the test code. Optional.jar: Ant use of the auxiliary package, including some additional TASK. The method of adding the package is simple, using the Explorer to drag the JAR file into the lib directory in the web-inflight of the Web directory. MyEclipse automatically adds all the JAR files in the directory to the Compilation ClassPath in the Project. Note that except for the packets, please join the project in front of the package. Since it is used to use Tomcat, the XML package in the mustable package can not be added. As shown below:

Join the JDBC driver for web applications

The previously prepared Oracle driver package is also added to the web project. Mainly these two files:

NLS_Charset12.jar ojdbc14.jar

The picture below is a list of configured the last package, please check one by one:

Configure Hibernate configuration files

Configure Hibernate database connection configuration

The connection configuration of the database is very simple, establish an XML file in the SRC directory of the project, named hibernate.cfg.xml. The content of this file is:

net.sf.hibernate.dialect.Oracle9Dialect oracle. JDBC.Driver.Oracledriver hd ABC JDBC : Oracle: Thin: @localhost: 1521: HDORC 1 50 30 true < Mapping resource = "COM / huangdong / demo / dao / sysuser.hbm.xml" /> We explain one by one for each property element:

Diagect: Used Oracle9 Configuring Connection.driver_Class: Oracle's JDBC Drive Class Name Connection.userName: Oracle Database Access User Name Connection.Password: Oracle Database Access Password Connection.URL: Oracle Database Access URL Connection.Pool.Size: Database connection Pool size statement_cache.size: JDBC Statement buffer size JDBC.FETCH_SIZE: Set the number of records that JDBC's statement read data JDBC.BATCH_SIZE: Set the batch delete, bulk update and batch quantity of the database Batch size show_sql when inserted: Set whether to display the SQL statement submitted to the database on the console, which is a list of mapped files that we have a map of the database table when developing commissioning. We will map the sysuser table below, so now it has been added. And this XML will be placed in the com.huangdong.demo.dao package, so you have to write the path when LOAD. Configure the Hibernate table map

Select the sysuser table in the Database Access View, select Generate HBM files in the menu:

Enter the relevant information in the wizard dialog box:

After completing the button, you will generate the sysuser class and the sysuser.hb.xml file in the com.huangdong.demo.dao package.

Since there are many inconvenient places in Java using java.util.date, I changed the Java attribute after LastLogin's map to Calendar.

This is a modified sysuser.hbm.xml file:

This is the modified SYSUSER.JAVA file:

package com.huangdong.demo.dao; import java.io.Serializable; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang .builder.ToStringBuilder; / ** @author Hibernate CodeGenerator * / public class SysUser implements Serializable {/ ** identifier field * / private String userid; / ** persistent field * / private String username; / ** persistent field * / private String userpasword; / ** nullable persistent field * / private java.util.Calendar lastlogin; / ** full constructor * / public SysUser (java.lang.String username, java.lang.String userpasword, java.util.Calendar lastlogin) {this.username = username; this.userpasword = userpasword; this.lastlogin = lastlogin;} / ** default constructor * / public SysUser () {} / ** minimal constructor * / public SysUser (java.lang.String username, Java.lang.String UserPasword) {this.username = username; this.userPasword = Userpasword;} public java.lang.string getUserId () {Retur n this.userid;} public void setUserid (java.lang.String userid) {this.userid = userid;} public java.lang.String getUsername () {return this.username;} public void setUsername (java.lang.String username) {this.username = username;} public java.lang.String getUserpasword () {return this.userpasword;} public void setUserpasword (java.lang.String userpasword) {this.userpasword = userpasword;} public java.util. Calendar getLastlogin () {return this.lastlogin;} public void setLastlogin (java.util.Calendar lastlogin) {this.lastlogin = lastlogin;} public String toString () {return new ToStringBuilder (this) .append ( "userid", getUserid ()) .tostring ();

} Public boolean equals (Object other) {if return false ((other instanceof SysUser)!); SysUser castOther = (SysUser) other; return new EqualsBuilder () .append (this.getUserid (), castOther.getUserid ()). ISEquals ();} public int.come (). .append (getUserid ()) .tohashcode ()) .Tohashcode ();}}

Create a servlet framework

Use the wizard of the New Servlet to create a test-used servlet, the following image is the parameters and options you entered when you create a servlet:

In the next XML Wizard dialog box, you can remember that DISPLAY NAME and DESTEM FUNCTION Servlet are cleared, as shown below:

This creates an initial servlet framework.

Write a database connection acquisition class

We write a separate class that allows database connection session from SessionFactory. This class name is Hibernateutil, we put it in com.huangdong.demo.util package, the specific code is as follows:

package com.huangdong.demo.util; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.cfg.Configuration; public class HibernateUtil {private static final SessionFactory sessionFactory; static {try {sessionFactory = new Configuration () configure () buildSessionFactory ();} catch (HibernateException ex) {throw new RuntimeException ( "Exception building SessionFactory:".. ex.getMessage (), ex);}} public static final ThreadLocal session = new ThreadLocal (); public static Session currentSession () throws HibernateException {Session s = (Session) session.get (); // Open a new Session, if this Thread has none yet IF (s == null) {s = sessionFactory.opensession (); session.set (s);} returniti} public static void closesession () throws hibernateException {session s = (session) session.get (); session .set (NULL); if (s! = null) s.close ();}}

We can get database connections through the currentSession method. If there is available session in the system, it will be reversed back, and a new session will be created if it is not. When the SESSION operation is complete, the operator is required to use the CloseSession method to release the session used. Establish test bean

Next we create a TestHibernate Java bean, which mainly adds some Hibernate test methods. The following is the information created by this class:

We join a way to add data to the database:

public boolean TestAdd () {try {Session session = HibernateUtil.currentSession (); Transaction tx = session.beginTransaction (); SysUser user = new SysUser (); user.setUsername ( "Ya-Ya"); user.setUserpasword ( "uhkuhkqepdwqi "); user.SetLastLogin (Calendar.GetInstance ()); session.save (user); tx.commit (); hibernateutil.closesis ();} catch (HibernateException E) {E.PrintStackTrace (); return false;} Return True;}

The first time I wrote this code very unexpectedly, I always feel more, but I really do this, we only use such a few words to add a record to the database.

Tune TestAdd method in servlet

This is very simple, change the Doget method for the TestServlet.java class, initialize the TestHibernate class, and call the TestAdd method:

public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType ( "text / html; charset = GBK"); PrintWriter out = response.getWriter (); out.println ( " "); Out.Println (" "); Out.Println (" a servlet </ title> </ Head> "); OUT.Println (" <body> "); // Call Test Add TestHibernate test = new testHibernate (); out.println (" TestAdd: " Test.TestAdd () " <p> ") Out.println ("</ body>"); out.println ("</ html>"); out.flush (); out.close ();}</p> <p>If the TestAdd method performs success, it will return TRUE on the page, otherwise false will be returned. Let's test one below.</p> <p>Test our first servlet-based Hibernate app boot Tomcat</p> <p>If you are configured by this article, you will not have any problems here. If you operate, you will enter the debug view of Eclipse:</p> <p>See all threads in the Debug view and see "Starting Coyote HTTP / 1.1 On Port 8080" in the console window indicates that Tomcat starts successful and listened to 8080 ports, as shown below:</p> <p>Open the browser and enter: in the address bar:</p> <p>Http: // localhost: 8080 / demo / servlet / testservlet</p> <p>If the returned page is shown below, the database update is successful:</p> <p>At the same time we can see Hibernate's log output in the console of Eclipse, explain the details of its work:</p> <p>2003-12-26 15:10:37 net.sf.hibernate.cfg.Environment <clinit> Information: hibernate 2.1.1 2003-12-26 15:10:37 Net.sf.hibernate.cfg.environment <clinit> Information: hibernate.properties NOT Found 2003-12-26 15:10:37 Net.sf.Hibernate.cfg.Environment <Clinit> Information: Using CGLIB Reflection Optimizer 2003-12-26 15:10:37 Net.sf.hibernate .cfg.Configuration configure information: configuring from resource: /hibernate.cfg.xml 2003-12-26 15:10:37 net.sf.hibernate.cfg.Configuration getConfigurationInputStream information: Configuration resource: /hibernate.cfg.xml 2003- 12-26 15:10:38 net.sf.hibernate.cfg.configuration addresource information: mapping resource: com / huangdong.hbm.xml 2003-12-26 15:10:38 Net.sf. hibernate.cfg.Binder bindRootClass information: Mapping class: com.huangdong.demo.dao.SysUser -> SYSUSER 2003-12-26 15:10:39 net.sf.hibernate.cfg.Configuration doConfigure information: Configured SessionFactory: null 2003 -12-26 15:10:39 Net.sf.hibernate.cfg.configuration secondpasscompile information: Processing One-to-Many Association Mappings 20 03-12-26 15:10:39 net.sf.hibernate.cfg.configuration secondpassCompile Information: Processing One-to-One Association Property References 2003-12-26 15:10:39 Net.sf.hibernate.cfg.configuration SecondPassCompile Information: Processing Foreign Key Constraints 2003-12-26 15:10:39 Net.sf.Hibernate.DiaLect.DiaLect <init></p> <p>Information: using dialact: net.sf.hibernate.diaalect.racle9diaalect 2003-12-26 15:10:39 net.sf.hibernate.cfg.SettingsFactory BuildSettings Information: JDBC Result Set Fetch Size: 50 2003-12-26 15: 10:39 net.sf.hibernate.cfg.SettingsFactory buildSettings information: Use outer join fetching: true 2003-12-26 15:10:39 net.sf.hibernate.connection.DriverManagerConnectionProvider configure information: Using Hibernate built-in connection pool (NOT for production us!) 2003-12-26 15:10:39 net.sf.hibernate.Connection.driverManagerConnectionProvider Configure Information: Hibernate Connection Pool Size: 20 2003-12-26 15:10:39 Net.sf.hibernate .connection.DriverManagerConnectionProvider configure information: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc: oracle: thin: @localhost: 1521: hdorc 2003-12-26 15:10:39 net.sf.hibernate.connection. DriverManagerConnectionProvider Configure Information: Connection Properties: {user = HD, Password = ABC, POOL.SIZE =</p> <p>1} 2003-12-26 15:10:39 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup information: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended) 2003-12-26 15 : 10: 45 Net.sf.hibaRnate.cfg.SettingsFactory BuildSettings Information: Use Scrollable Result Sets: True 2003-12-26 15:10:45 Net.sf.Hibernate.cfg.SettingsFactory BuildSettings Information: JDBC 2 Max Batch Size: 30 2003-12-26 15:10:45 Net.sf.hibFactory.cfg.SettingsFactory BuildSettings Information: echoing all sql to stdout 2003-12-26 15:10:45 net.sf.hibernate.cfg.SettingsFactory BuildSettings information: Query Language Substitutions: {} 2003-12-26 15:10:45 Net.sf.hibernate.cfg.SettingsFactory BuildSettings Information: cache provider: Net.sf.ehcache.hibernate.Provider 2003-12-26 15:10:45 Net.sf.hibernate.cfg.Configuration ConfigureChes Information: Instantiating and configuring caches 2003-12-26 15:10:46 net.sf.hibernate.impl.SessionFactoryImpl <init> information: building session factory 2003-12-26 15: 10:47 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance information: no JNDI name configured Hibernate: (????,,,) Insert into SYSUSER (username, userpasword, lastlogin, userid) values ​​in the end we can see Hibernate The generated database operation statement. I can say that you have successfully run a lot of things. Let us listen again, please consider how they are running and deployed by you, what are they:</p> <p>Eclipse MyEclipse Tomcat Oracle / Oracle JDBC Driver Hibernate Struts (in fact, we have not used its feature yet)</p> <p>View whether the data in the table is updated</p> <p>View the data in the data table in the Database Access View in the Database Access View:</p> <p>This will see the data in the sysuser table in Database Data View:</p> <p>Stay in the final</p> <p>This article simply introduces you to the development of Java-based web applications, and introduces a series of development tools and components. These tools have more features, this is no longer introduced, please refer to Eclipse, MyEclipse documentation, and there are many rich features. Two powerful components of Struts and Hibernate are later slowly illustrated in subsequent articles.</p> <p>If you have any comments and suggestions for this article, please contact me, tell me your thoughts, and can also discuss various technologies related to Java in the Java version of the technology sky BBS. You can download it from here to a complete Eclipse Project package.</p> <p>In addition, all code herein is not issued by the author's actual test in the following environments:</p> <p>Eclipse 2.1.2 Struts 1.1 Hibernate 2.1.1 Tomcat 4.1.29 / Jetty 4.2.15 com.tanghan.plugin_0.1.0.12.21 JDK 1.4.2_02 For Windows / FreeBSD 4.8 / FreeBSD 4.9 FreeBSD 4.8 / FreeBSD 4.9 / Windows 2000 / Windows XP Oracle 9.2.0.1.0</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-7665.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="7665" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.048</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'ZOTWms12GIND0W3bJ3d5wzvmGxnq4Sm3Ff8YH_2BxUEqisCYI28ALSatmoUR5HfN8r5MowSe_2BVkT4sd3Lg'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>