JSPSmartupload upload download full Raiders (reproduced)

xiaoxiao2021-03-06  60

First, installation articles

JSPSmartupload is

Www.jspsmart.com The website developed a free use full-featured file upload download component, adapted to embed the JSP file that performs upload download operations. This component has the following features:

1, easy to use. Only writing three five lines of Java code in the JSP file, you can get upload or download it, it is convenient.

2, can control upload. With the objects provided by the JSPSmartupLoad component, you can get information on all uploaded files (including file name, size, type, extension, file data, etc.) for easy access.

3, can limit the uploaded documents in size, type and other aspects. This can be filtered off the files that do not meet the requirements.

4, flexible download. Only write two lines of code, you can turn the web server into a file server. No matter whether the file is in the directory of the web server or in any other directory, JSPSMARTupLoad can be downloaded.

5. Upload the file to the database, you can also download the data in the database. This function is for the mysql database because it is not versatile, so this article is not prepared to introduce this usage.

JSPSMARTUPLOAD components can be from

Www.jspsmart.com website free download, the name of the compressed package is jspsmartupload.zip. After downloading, use Winzip or WinRAR to extract it to Tomcat's WebApps directory (this article is described as an example of Tomcat Server). After decompression, change the subdirectory Web-INF in the WebApps / Jspsmartupload directory to all-in-case WEB-INF, so you can change the JSPSMARTupLoad class. Because Tomcat is sensitive to file name sensitive, it requires web applications related to the directory to Web-INF, and must be uppercase. Then restart Tomcat so that you can use the JSPSmartupload component in the JSP file.

Note that after the above method is installed, only the program in the WebApps / JSPSmartupLoad directory can use the JSPSMARTupload component, if you want to use all Web applications of the Tomcat server to use it, you must do the following:

1. Enter the command line status, switch the directory to the Tomcat's WebApps / JSPSMARTUPLOAD / Web-INF directory.

2. Run JAR packaging command: JAR CVF JSPSMARTUPLOAD.JAR COM

(You can also open the resource manager, switch to the current directory, compress all the files under the COM directory into jspsmartupload.zip with WinZip, and then rename the jspsmartupload.zip to jspsmartupload.jar files.)

3. Copy JSPSmartupload.jar to Tomcat's Shared / Lib Directory.

Second, related classes

(I) File class

This class wraps all the information for uploading the file. Through it, you can get the file name, file size, extension, file data, etc. of the upload file.

The File class mainly provides the following methods:

1, SaveAs effect: Save the file.

prototype:

Public void saveas (java.lang.string destfilepathname)

or

Public void saveas (java.lang.string destfilepathname, int optionsaveas)

Where DESTFILEPATHNAME is saved file name, Optionsaves is a saved option, which has three values, Saveas_Physical, SaveAs_Virtual, Saveas_Auto. SaveAs_physical indicates that the root directory of the operating system is saved as the file root directory, and saveas_virtual indicates that the root directory is saved by the root directory of the web application, and SaveAs_Auto means that the component is determined, and when the root directory of the web application exists When it chooses SaveAs_virtual, otherwise SaveAs_physical will be selected. For example, if the SaveAs ("/ UPLOAD / SAMPLE.ZIP", SaveAs_Physical) If the web server is installed in the C drive, the saved file name is actually C: /upload/sample.zip. And SaveAs ("/ upload / sample.zip", saveas_virtual) If the root directory of the web application is WebApps / JSPSmartupload, the saved file name is actually WebApps / JSPSmartupload / Upload / Sample.zip. SaveAs ("/ UPLOAD / SAMPLE.ZIP", SAVEAS_AUTO) If there is an UPLOAD directory in the web application root directory, its effect is the same as saveas ("/ upload / sample.zip", saveas_virtual), otherwise Saves ("/ UPLOAD / SAMPLE.ZIP ", SaveAs_physical).

Recommendation: For the development of web programs, it is best to use SaveAs_virtual to transplant.

2, ISMissing

Role: This method is used to determine if the user selects the file, that is, the corresponding form item is worthless. When the file is selected, it returns false. When the file is not selected, it returns True.

Prototype: public boolean ismissing ()

3, getfieldname

Role: Take the name of the form item corresponding to this uploaded file in the HTML form.

Protocol: public string getfieldname ()

4, getFilename

Role: Take the file name (excluding directory information)

Prototype: public string getFileName ()

5, getfilepathname

Role: Take a full name (with directory)

Prototype: Public String getFilePathname

6, getfileext

Role: Take a file extension (suffix)

Prototype: public string getfileext ()

7, getSize

Role: Take the length of the file (in bytes)

Prototype: public int getsue ()

8, GetBinaryData

Role: Take a byte of the file data in the file data to detect files.

Prototype: Public Byte GetBinaryData (int index). Among them, Index represents the displacement, its value is between 0 and GetSize () - 1.

(Ii) Files class

This class represents the collection of all uploaded files, which can be obtained by the number, size, etc. of the upload file. There are the following methods:

1, getCount

Role: Number of uploaded documents.

Prototype: public int getCount ()

2, getfile effect: obtain the file object file in the specified displacement (this is com.jspsmart.upload.file, not java.io.file, pay attention to distinguish).

Prototype: Public File GetFile (int index). Where index is a pointing, its value is between 0 and GetCount () - 1.

3, Getsize

Role: Take the total length of the upload file, which can be used to limit the amount of data amount uploaded.

Prototype: Public long getSize ()

4, getCollection

Role: Return all uploaded file objects in the form of Collection so that other application references, browse uploaded file information.

Prototype: Public Collection getCollection ()

5, getENUMERATION

Role: Return all uploaded file objects in ENUMERATION (enumeration) so that other applications browse uploaded file information.

Prototype: public enumeration getenumeration ()

㈢ Request class

This class is equivalent to the object Request in JSP built-in. Only, this class is provided because the value of the form item cannot be obtained through the Request object for the file upload form. It must be obtained by the Request object provided by the JSPSmartupLoad component. This class provides the following method:

1, getParameter

Role: Get the value of the specified parameter. When the parameter does not exist, the return value is NULL.

Prototype: Public String getParameter (String name). Where Name is the name of the parameter.

2, getParameterValues

Role: When a parameter can have multiple values, use this method to take the value. It returns a string array. When the parameter does not exist, the return value is NULL.

Prototype: public string [] getParameterValues. Where Name is the name of the parameter.

3, getParameternames

Role: Get all the names of all parameters in the Request object, used to traverse all parameters. It returns an enumerated object.

Prototype: public enumeration getParameterNames ()

㈣ SmartUPload class This class completes upload download work.

A. Upload and download shared methods:

There is only one: Initialize.

Role: Execute the initialization work of upload download, must be the first execution.

Prototype: There are multiple, mainly using this:

Public final void initialize (javax.servlet.jsp.pagecontext pagecontext)

Among them, PageContext is a JSP page built-in object (page context).

B. Uploading the method for use:

1, UPLOAD

Role: Upload file data. For upload operations, the first step is executed, and the second step is to perform this method.

Prototype: public void upload ()

2, Save

Role: Save all upload files to the specified directory and return the number of files saved.

Prototype: public int save (String destPathname)

And Public int Save (string destpathname, int option) where destPathname is a file saved directory, Option is saved, which has three values, Save_Physical, Save_Virtual and Save_AUTO. (Similar to the value of the SaveAs method of the FILE class) Save_physical indicates that the component saves the file to the directory of the operating system root to the root directory, save_virtual indicates that the file saves the file to the web application root directory as the file root directory. In the directory, Save_AUTO indicates automatic selection by the component.

Note: The effect of Save is equivalent to Save (Destpathname, Save_AUTO).

3, Getsize

Role: Take the total length of the upload file data

Prototype: public int getsue ()

4, getfiles

Role: Take all uploaded files, return to the Files object, can use the Files class's operation method to get information such as the number of uploaded files.

Prototype: public files getFiles ()

5, getRequest

Role: Take the Request object so that this object obtains the value of the upload form single parameter.

Prototype: public request getRequest ()

6, setallowedfileslist

Role: Set the file that allows uploading with a specified extension, and when the file name is not allowed during the upload, the component will throw an exception.

Protocol: public void setallowedfileslist (String allowedFilesList)

Among them, AllowedFileSlist is a comma-separated list of file extensions to allow uploaded file extensions. If you want to allow files that do not have extensions, you can use two comma. For example: SETALLOWEDFILSLIST ("DOC, TXT,") will allow files with DOC and TXT extensions and files without extensions.

7, setdeniedfileslist

Role: Used to limit the uploading files with specified extensions. If there is a file extension being restricted, the upload component will throw an exception.

Protocol: public void setdeniedFilesList (String DeniedFileSlist)

Among them, DeniedFileSlist is a comma-separated comma in the disabled file extension list. If you want to prohibit uploading files that do not have extensions, you can use two commas to represent. For example: SetDeniedFileSlist ("EXE, BAT,") will disable files with EXE and BAT extensions and files without extensions.

8, SetMaxFileSize

Role: Set the maximum length of each file to allow upload.

Prototype: Public void setMaxFileSize (Long MaxFileSize)

Among them, MaxFileSize is the maximum length of uploading for each file. When the file exceeds this length, it will not be uploaded.

9, SetTotalMaxFileSize

Role: Set the total length of the file that allows uploaded files to limit the amount of data amounts uploaded.

Prototype: Public void setTotalMaxFileSize (Long TotalmaxFileSize)

Among them, TotalmaxFileSize is the total length of the file that allows upload.

C. Download file common method

1, SetContentDisPosition

Role: Add data to the Content-Disposition Domain of the MIME file header. The JSPSMARTupLoad component automatically fills in the Content-Disposition Domain of the MIME File Header when the download is returned. If the user needs to add additional information, use this method. Prototype: Public void setContentDisPosition (String ContentDisPosition)

Where contentdisposition is the data to be added. If contentdisposition is null, the component will automatically add "attachment;" to indicate that the downloaded file as an attachment, the result is that the IE browser will prompt the file instead of automatically opening this file (IE browser usually according to the downloaded file The extension decides what operations are executed, the extension is that the DOC will open with the Word program, and the extension will open with the Acrobat program, and so on).

2, Downloadfile

Role: Download file.

Prototype: A total of three prototypes available, the first most common, the latter two file downloads for special circumstances (such as changing the content type, change the saved file name).

1 Public void Downloadfile (String SourceFilepathname)

Among them, SourceFilePathname is the file name (with directory file full name)

2 Public void Downloadfile (String SourceFilepathname, String ContentType)

Among them, SourceFilePathname is the file name (full name with directory) to download, and contentType is the content type (file type information in MIME format, can be identified by browser).

3 Public Void Downloadfile (String SourceFilepathname, String ContentType, String Destfilename)

Among them, SourceFilePathname is the file name (full name with the directory) to download, contentType is the content type (file type information in MIME format, can be identified by browser), DestFileName is the default saving file name.

Third, the file is uploaded

(1) form request

There are two requirements for the FORM form for uploading files:

1, Method Apply POST, Method = "POST".

2, increase attributes: encType = "multipart / form-data"

Below is an example of a Form form for uploading files:

Action = "/ jspsmartupload / upload.jsp">

(Ii) the example uploaded

1, upload page Upload.html

This page provides a form that allows the user to select the file you want to upload, and click the "Upload" button to perform the upload operation.

The page source code is as follows:

File name: Upload.html

Servers: Vanguage Software Production Center Yuizhi (

Zhsoft88@sohu.com)

->

file upload </ title></p> <p><meta http-equiv = "content-type" content = "text / html; charSet = GB2312"></p> <p></ hEAD></p> <p><body></p> <p><p> </ p></p> <p><p align = "center"> Upload file selection </ p></p> <p><Form method = "post" Action = "jsp / do_upload.jsp"</p> <p>ENCTYPE = "Multipart / Form-Data"></p> <p><Input Type = "Hidden" name = "test" value = "good"></p> <p><Table Width = "75%" border = "1" align = "center"></p> <p><tr></p> <p><TD> <div align = "center"> 1,</p> <p><Input Type = "file" name = "file1" size = "30"></p> <p></ div> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> <div align = "center"> 2,</p> <p><Input Type = "file" name = "file2" size = "30"></p> <p></ div> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> <div align = "center"> 3,</p> <p><Input Type = "file" name = "file3" size = "30"></p> <p></ div> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> <div align = "center"> 4,</p> <p><Input Type = "file" name = "file4" size = "30"></p> <p></ div> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> <DIV Align = "Center"></p> <p><Input Type = "Submit" Name = "Submit" Value = "upload it!"></p> <p></ div> </ td></p> <p></ TR></p> <p></ TABLE></p> <p></ Form></p> <p></ body></p> <p></ html></p> <p>2, upload processing page DO_UPLOAD.JSP</p> <p>This page performs a file upload operation. The usage of the upload method is described in detail in the page source code, and details will not be described here. The page source code is as follows:</p> <p><%</p> <p>File name: do_upload.jsp</p> <p>Servers: Vanguage Software Production Center Yuizhi (</p> <p>Zhsoft88@sohu.com)</p> <p>-%></p> <p><% @ Page ContentType = "Text / HTML; Charset = GB2312" Language = "JAVA"</p> <p>Import = "java.util. *, com.jspsmart.upload. *" ErrorPage = ""%></p> <p><html></p> <p><HEAD></p> <p><title> File Upload Process page </ Title></p> <p><meta http-equiv = "content-type" content = "text / html; charSet = GB2312"></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>// Newly build a smartupload object</p> <p>Smartupload su = new smartupload ();</p> <p>// Upload initialization</p> <p>Su.initialize (PageContext);</p> <p>/ / Set up the upload limit</p> <p>/ / 1. Limit the maximum length of each upload file.</p> <p>// Su.SetMaxFileSize (10000);</p> <p>// 2. Restrict the length of the total upload data.</p> <p>// Su.SettotalMaxFileSize (20000);</p> <p>// 3. Set the file that allows upload (by extension), only the DOC, TXT file is allowed.</p> <p>// Su.setAllowedFileSlist ("DOC, TXT");</p> <p>// 4. Set the file prohibited from upload (limited by extension), prohibit uploading EXE, BAT,</p> <p>JSP, HTM, HTML extension files and files without extensions.</p> <p>// Su.SetdeniedFileSlist ("EXE, BAT, JSP, HTM, HTML,");</p> <p>// upload files</p> <p>Su.upload ();</p> <p>// Save all uploaded files to the specified directory</p> <p>INT count = Su.save ("/ upload");</p> <p>Out.println (count "file upload success! <br>");</p> <p>// Use the Request object to get the value of parameters</p> <p>Out.println ("Test =" Su.GetRequest (). getParameter ("test")</p> <p> "<BR> <BR>");</p> <p>// Extract upload file information one by one, and save the file.</p> <p>For (int i = 0; i <su.getfiles (). getCount (); i )</p> <p>{</p> <p>com.jspsmart.upload.file file = su.getfiles (). getFile (i);</p> <p>// Continue if there is no existence</p> <p>File.isming ()) Continue;</p> <p>// Display current file information</p> <p>Out.println ("<Table Border = 1>");</p> <p>Out.println ("<TR> <TD> FieldName </ TD> <TD>"</p> <p> file.getfieldname () "</ td> </ tr>");</p> <p>Out.println ("<tr> <td> file length (size) </ td> <TD> file.getsize () " </ td> </ tr> ");</p> <p>Out.println ("<tr> <td> file name (filename </ td> <td>"</p> <p> file.getFileName () "</ td> </ tr>");</p> <p>Out.println ("<tr> <td> file extension (fileext) </ td> <td></p> <p> file.getfileext () "</ td> </ tr>");</p> <p>Out.println ("<tr> <td> file full name </ td> <td>"</p> <p> file.getfilepathname () "</ td> </ tr>");</p> <p>Out.println ("</ Table> <BR>");</p> <p>// Save the file</p> <p>// file.saveas ("/ upload /" myfile.getfilename ());</p> <p>// Save to the directory of the root directory as the root of the web application</p> <p>// file.saveas ("/ upload /" myfile.getFileName (),</p> <p>Su.save_virtual);</p> <p>/ / Save to the root directory of the operating system to the file root directory</p> <p>// file.saveas ("c: // temp //" myfile.getFileName (),</p> <p>Su.save_physical;</p> <p>}</p> <p>%></p> <p></ body></p> <p></ html></p> <p>Fourth, file download</p> <p>1, download link page down, Download.html</p> <p>The page source code is as follows:</p> <p><! -</p> <p>File name: Download.html</p> <p>Servers: Vanguage Software Production Center Yuizhi (</p> <p>Zhsoft88@sohu.com)</p> <p>-></p> <p><! Doctype html public "- // w3c // DTD HTML 4.01 Transitional // En"></p> <p><html></p> <p><HEAD></p> <p><Title> Download </ Title></p> <p><meta http-equiv = "content-type" content = "text / html; charSet = GB2312"></p> <p></ hEAD></p> <p><body></p> <p><a href="jsp/DO_DOWNLOAD.JSP"> Click to download </A></p> <p></ body></p> <p></ html></p> <p>2, download processing page do_download.jsp do_download.jsp shows how to download files with JSPSMARTupload components, you can see from the source code below, and how simple downloads.</p> <p>The source code is as follows:</p> <p><% @ Page ContentType = "text / html; charset = GB2312"</p> <p>Import = "com.jspsmart.upload. *"%> <% // New a smartupload object</p> <p>Smartupload su = new smartupload ();</p> <p>// Initialization</p> <p>Su.initialize (PageContext);</p> <p>// Set contentdisposition to NULL to prohibit the browser automatically open the file,</p> <p>/ / Ensure that the click link is the download file. If it is not set, the downloaded file extension is called</p> <p>// DOC, the browser will automatically open it with Word. When the extension is PDF,</p> <p>// The browser will open with Acrobat.</p> <p>Su.setContentDisPosition (NULL);</p> <p>// download file</p> <p>Su.Downloadfile ("/ UPLOAD / How to earn my first bucket of gold.doc");</p> <p>%></p> <p>Note that the downloaded page is executed, outside the Java script range (ie <% ...%>), do not include characters such as HTML code, space, carriage return, and wrap, and some words will not be downloaded correctly. If you don't believe it, you can add a newline character in the above source code, and then download it, and ensure an error. Because it affects the data stream returned to the browser, it causes the parsing error.</p> <p>3, how to download Chinese files</p> <p>JSPSMARTupload can download files, but it is insufficient to support Chinese. If there is Chinese characters in the downloaded file name, the browser shows a bunch of garbled when prompted the file name, which is very sweeping. The above example is this. (This problem is also the problem exists in many download components, very few people solve, no relevant information, sigh!)</p> <p>In order to add support for the JSPSmartupLoad component, I studied the component and found that the browser can display the Chinese name correctly after the UTF-8 encoding returns the safer file name of the browser. This is a delighted discovery. So I made an upgrade process for the Smartupload class of the JSPSmartupLoad component, adding the TOUTF8STRING method, the change part source code is as follows:</p> <p>Public Void Downloadfile (String S, String S1, String S2, INT i)</p> <p>Throws ServleTexception, IOException, Smartuploadexception</p> <p>{</p> <p>IF (s == NULL)</p> <p>Throw New IllegalargumentException ("File '" S </p> <p>"'NOT FOUND (1040).");</p> <p>IF (S.Equals ("))</p> <p>Throw New IllegalargumentException ("File '" S </p> <p>"'NOT FOUND (1040).");</p> <p>IF (! isvirtual (s) && m_denyphysicalpath)</p> <p>Throw New SecurityException ("Physical Path IS</p> <p>DENIED (1035). ");</p> <p>IF (isvirtual (s))</p> <p>s = m_application.getRealPath (s);</p> <p>Java.io.file file = new java.io.file (s);</p> <p>FileInputStream FileInputStream = New FileInputStream (file);</p> <p>Long L = file.Length (); boolean flag = false;</p> <p>INT K = 0;</p> <p>Byte abyte0 [] = new byte</p> <p>; If (s1 == null) m_response.setContentType ( "application / x-msdownload"); else if (s1.length () == 0) m_response.setContentType ( "application / x-msdownload"); else m_response.setContentType (s1); m_response.setContentLength ((int) l); m_contentDisposition = m_contentDisposition = null m_contentDisposition:!? "attachment;"; if (s2 == null) m_response.setHeader ( "Content-Disposition", m_contentDisposition "filename = " toUtf8String (getFileName (s))); else if (s2.length () == 0) m_response.setHeader (" Content-Disposition ", m_contentDisposition); else m_response.setHeader (" Content-Disposition ", m_contentDisposition " FileName = " TOUTF8STRING (S2)); While ((long) k <l) {Int j = fileinputstream.read (Abyte0, 0, i); k = j; m_response.getOutputStream (). Write (Abyte0, 0 , j);} fileInputstream.close ();} / ** * converts Chinese characters in the file name into UTF8 encoded strings to download the saved file name correctly. * Violence 2003.08.01 * @Param s Original File Name * @return Recode File Name * / Public Static String Toutf8String (String S) {StringBuffer SB = New StringBuffer (); for (INT i = 0 i <s.length (); i ) {char c = s.Charat (i); if (c> = 0 && c <= 255) {sb.append (c);} else {byte [] B; Try {b = character.toString (c) .getbytes ("UTF-8");} catch (exception ex) {system.out.println (ex); b = new byte [0];} for (int J = J <</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-118971.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="118971" 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.032</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 = '1oR3c8tKzOXU3A4G2EZ1GGF4r4Z3Dg18f_2BMdJmgFVSYR1890d_2BxLD6x4GVTmY9x_2BOLNLaXcHX0MTYa8J1GRWfQ_3D_3D'; 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>