A complete news release system (1)

xiaoxiao2021-03-05  20

A complete press release system

Keywords: JSP, Java, Press Release Environment: Tomcat 5.5.7 J2se 5.0 PostgreSQL 8.0

I will take a few steps to complete the build of a press release system, understand some basic methods of JSP!

First of all, I will first introduce the basic structure of this press release system:

Index.jsp: Admin Land Interface Check.jsp: Verify Administrator identity main.jsp: Administrator adds news page Pub.jsp: Page Display: Show all news

The background of the background is mainly:

DB.java: Database Connection MD5.java: MD5 Algorithm Pubbean.java: Release CheckBean.java: Verify login identity

That is, you can complete the basic feature of a press release system when you go from index -> main-> display.

I don't write the title and content of the news to the database, because the resources of the database system are too expensive, and the number is always read when visiting

According to the library, it is very hard, I wrote the news into a separate HTM file, then written the title and the name of the HTM file!

And how does the name of this HTM file are randomly generated? I chose the MD5 algorithm because the title of each news will not be the same, so the only one is guaranteed.

Sex!

Below I first put out the basic framework of this system, saying big, it seems to be the "system" "kernel"! :)

================ Database section ===================

Create Table Administrator (Admin Char (16), "Password" CHAR (32)) WITHOUT OIDS; ALTER TABLE Administrator Owner To Admin;

Create Table News (Title Char (255), Page CHAR (255)) WITHOUT OIDS; ALTER TABLE NEWNER TO Admin Admin

================ Program part ==================

Package login;

Import java.sql. *;

Public class db {

Private connection conn; private resultset {type {class.forname ("org.postgreSql.driver); conn = drivermanager.getConnection

("JDBC: PostgreSQL: // LocalHost: 5432 / News? User = admin"); stmt = conn.createstatement ();} catch (exception e) {system.out.println (e);}} public void update (String SQL) {Try {stmt.executeUpdate (SQL);} catch (exception e) {system.out.println (e);}} public resultset quarry (String SQL) {Try {= stmt.executeQuery (SQL) Catch (Exception E) {system.out.println (e);} RETURN RS;}} package login

Import java.sql. *; import java.io. *;

Public class pubbean {private limited title, context; private db db; private md5 md5; public pubbean () {db = new db (); md5 = new md5 ();} public void settitle (String title) {this.title = PUBLIC VOID SETCONTEXT (STRING CONTEXT) {this.context = context;}

Public void Pubit () {TRY {Title = New String (Title.getbytes ("8859_1"), "GB2312"); Context = New String (Context.getbytes ("8859_1"), "GB2312"); string titlemd5 = MD5 .getKeyBeanofstr (Title); DB.Update (" Title ", '" TitleMd5 ") "); string file =" news // Ice " titlemd5 ". htm "; PrintWriter PW = new printstream (file); PW.Println ("" Title "</ Title>"); PW.Println (Context); PW.Close ();} catch (Exception E) {System.out.println (e);}}}</p> <p>Package login;</p> <p>Import java.sql. *;</p> <p>public class CheckBean {private String message = "", admin, password; private DB db; public CheckBean () {db = new DB ();} public void setAdmin (String admin) {this.admin = admin;} public void setPassword (String password) {this.password = password;} public string checkit () {Try {resultset = db.quarry ("Select * from administrator whereadmin = ' this.admin "); while (rs.next ()) {String PWS = rs.getstring ("password"). Trim (); if (this.paals (this.pals (this.pals)) {message = "Password is correct!";} Else message = "Password error!" Return Message;} Message = "Users do not exist!";} catch (exception e) {system.out.println (e);} returnome</p> <p>================ page part ===================</p> <p>INDEX.JSP:</p> <p><% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <HTML> <head> <title> Login System </ Title> </ head> <body> <form name = "login" action = "check .jsp "Method =" post "> User: <input type =" text "name =" admin "> <br> password: <input type =" password "name =" password "> <br> <input type =" Submit "Value =" Login "> <br> </ form> </ body> </ html> <% string error = request.getParameter (" error "); error = new string (Error.GetBytes (" 8859_1 ") , "GB2312"); if (error == null) {} else {%> <% = error%> <%}%></p> <p>Check.jsp</p> <p><% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "Login.checkbean"%> <% string admin = request.getParameter ("admin"); string password = request.getParameter ("Password");%> <jsp: usebean id = "checkbean" class = "login.checkbean" /> <jsp: setProperty name = "checkbean" proty = "value =" <% = admin.trim )%> "/> <jsp: setProperty name =" checkbean "proty =" password "value =" <% = password.trim ()%> "/> <% string result = checkbean.checkit (); if (Result .Equals ("Password is correct!")) {session.setttribute ("admin", admin); response.sendredirect ("main.jsp");} else {%> <jsp: forward page = "index.jsp"> <jsp: param name = "error" value = "<% = result%>" /> </ jsp: forward> <%}%> main.jsp</p> <p><% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% string admin = ("admin"); if (admin == null) {response.sendredirect ("Index .jsp ");} else {%> <html> <head> <title> News published </ title> </ head> <body> <form name =" pub "action =" Pub.jsp "Method =" POST "> Topic: <input type =" text "name =" title "> <br> Content: <textarea cols =" 100 "rows =" 10 "name =" context "> </ textarea> <BR> <input Type = "Submit" value = "Submit"> <br> </ form> </ body> </ html> <%}%></p> <p>Pub.jsp</p> <p><% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% string admin = (string); string title = request.getParameter ("title"); string context = Request.getParameter ("Context"); if (admin == null) {response.sendredirect ("index.jsp");} else {%> <jsp: usebean id = "pubbean" class = "login.pubbean" /> <Jsp: setProperty name = "Pubbean" Property = "title" value = "<% = title.trim ()%>" /> <jsp: setProperty name = "Pubean" Property = "Context" Value = "< % = context%> "/> <% pubbean.pubit (); response.sendredirect (" display.jsp ");}%> Display.jsp</p> <p><% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% class.forname ("sun.jdbc.odbc.jdbcodbcdriver); connection Conn = drivermanager.getConnection ("JDBC: ODBC: PostgreSQL", "" "); statement stmt = conn.createstatement ();%> <html> <head> <title> News </ title> </ head> <body> <% resultSet = stmt.executeQuery ("SELECT * from news"); // Displays the record while (rs.next ()) {output ("<a href = news / ice" gtstring (2) "HTM Target = _BLANK> rs.getstring</p> <p>(1) "</a>"); out.println ("<br>");}%> </ body> </ html></p> <p>Ok, the basic things are achieved, I hope I can give you a complete look. In the article, I will step by step.</p> <p>Perfection, add some new features!</p> <p>The following is the MD5 algorithm is found online, reproduced:</p> <p>Package login;</p> <p>Import java.lang.reflect. *;</p> <p>Public Class MD5 {/ * The following S11-S44 is actually a matrix of 4 * 4, which is implemented in the original C implementation. Here, it is intended to become STATIC final, which is read-only. Multiple Instance between the same process space * / static final int S11 = 7; Static Final Int S12 = 12; Static Final Int S13 = 17; Static Final Int S14 = 22; Static Final Int S21 = 5; Static Final INT S22 = 9; Static Final INT S23 = 14; Static Final Int S24 = 20;</p> <p>Static Final Int S31 = 4; Static Final Int S32 = 11; Static Final INT S33 = 16; Static Final Int S34 = 23;</p> <p>Static Final Int S41 = 6; Static Final Int S42 = 10; Static Final INT S43 = 15; Static Final Int S44 = 21;</p> <p>Static final Byte [] Padding = {-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; / * The following three members are the KEYBEAN calculation 3 core data used, is defined in the original C implementation to the KeyBean_CTX structure</p> <p>* / Private long [4]; // state (abcd) private long [] count = new long [2]; // number of bits, modulo 2 ^ 64 (LSB first) private bote [] Buffer = new byte [64]; // input buffer</p> <p>/ * DigestHexStr is the only public member of KeyBean, which is the 16-way ASCII representation of the latest calculation results. * / public string DigestHexStr;</p> <p>/ * Digest, is the latest internal representation of the 2-time calculation result, indicating the 128bit keybean value. * / private byte [] Digest = New Byte [16];</p> <p>/ * GetKeyBeanofstr is the most important public method of class KeyBean. The entrance parameters are the string of the keybean transformation returned to changed results, this result is obtained from the public member DigestHexStr. * / Public string getKeyBeanofstr (String Inbuf) {keybeaninit (); keybeanupdate (Inbuf.GetBytes (), INBUF.LENGTH ()); KeyBeanFinal ()); KeyBeanFinal (); DigestHexStr = ""; for (int i = 0; i <16; i ) ) {DigestHexStr = bytehex (Digest [i]);} Return DigestHexStr;} // This is a standard constructor of KeyBean class, JavaBean requires a PUBLIC and there is no parameter constructor PUBLIC MD5 () {KeyBeaninit () ;</p> <p>Return;}</p> <p>/ * KeyBeanInit is an initialization function that initializes variables core, loaded standard magic number * / private void keyBeanInit () {count [0] = 0L; count [1] = 0L; /// * Load magic initialization constants.</p> <p>State [0] = 0x67452301L; State [1] = 0xEfcdab89L; State [2] = 0x98badcfel; state [3] = 0x10325476L;</p> <p>Return;} / * f, g, h, and i are four basic KeyBean functions, in the original KeyBean C implementation, because they are simple bit operations, it may be achieved by the efficiency, In Java, we implemented them into a Private method, the name maintained in the original C. * /</p> <p>Private long f (long x, long y, long z) {return (x & y) | ((~ x) & z);</p> <p>} Private long g (long x, long y, long z) {return (x & z) | (Y & (~ z));</p> <p>} PRIVATE Long h (long x, long y, long z) {return x ^ y ^ z;}</p> <p>PRIVATE long I (long x, long y, long z) {return y ^ (x | (~ z));</p> <p>/ * FF, GG, HH and II will call F, G, H, i to conduct near-step transform FF, GG, HH, AND II TRANSFORMATIONS for Rounds 1, 2, 3, and 4. Rotation IS Separate from Addition to Prevent Recomputation * / Private long ff (Long A, Long B, Long C, Long D, Long X, Long S, Long AC) {A = F (B, C, D) X AC; A = ((INT ) A << s) | ((int) a >>> (32 - s)); A = B; Return A;</p> <p>PRIVATE Long GG (Long A, Long B, Long C, Long D, Long X, Long S, Long AC) {A = G (B, C, D) X AC; A = ((int) a < <s) | ((int) a >>> (32 - s)); A = B; RETURN A;} Private Long HH (Long A, Long B, LONG C, LONG D, Long X, Long S, Long AC) {a = h (b, c, d) x ac; a = (int) a << s) | (INT) A >>> (32 - s)); A = B; RETURN A; PRIVATE LONG II (LONG A, Long B, Long C, LONG D, Long X, Long S, long AC) {a = i (b, c, d) x ac; a = ((int) a >>> ((int) a >>> (32 - s)); A = B; Return A;} / * KeyBeanupdate is the main calculation process of KeyBean, Inbuf is the word to be transformed The knuckle, INPUTLEN is the length, this function is called by getKeyBeanofstr, and the keybeaninit needs to be called before calling it, so it is designed to private * / private void keybeanupdate (byte [] Inbuf, int {) {</p> <p>INT I, INDEX, PARTLEN; BYTE [] block = new byte [64]; index = (int) (count [0] >>> 3) & 0x3f; // * update number of bits * / if ((count) [0] = (Inputlen << 3)) <(Inputlen << 3)) count [1] ; count [1] = (Inputlen >>> 29); Partlen = 64 - INDEX;</p> <p>// Transform As Many Times As Possible. IF (Inputlen> = Partle) {KeyBeanMemcpy (Buffer, Inbuf, INDEX, 0, PartLEN); KeyBeantransform (Buffer);</p> <p>For (i = partlen; i 63 <inputlen; i = 64) {</p> <p>KeyBeanMemcpy (Block, Inbuf, 0, I, 64); KeyBeantransform (Block);} index = 0;</p> <p>Else</p> <p>i = 0;</p> <p>/// * buffer remaining input * / keybeanmemcpy (buffer, inbuf, index, I, inputlen - i);</p> <p>}</p> <p>/ * KeyBeanFinal organizes and fills out the result * / private void keybeanFinal () {byte [] bits = new byte [8]; int index, padlen;</p> <p>/// * Save Number of Bits * / Encode (BITS, COUNT, 8);</p> <p>/// * Pad out to 56 mod 64. Index = (int) (count [0] >>> 3) & 0x3f; padlen = (INDEX <56): (120 - index); keybeanupdate (Padding, Padlen);</p> <p>/// * append length * / keybeanupdate (BITS, 8);</p> <p>/// * Store State in Digest * / Encode (Digest, State, 16);</p> <p>}</p> <p>/ * KeyBeanMemcpy is a block copy function for internal use byte array, from INPOS, starting the LEN length byte to Output's Outpos location * /</p> <p>Private void keybeanmemcpy (Byte [] Output, Byte [] INPUT, INT OUTPOS, INT INPOS, INT LEN) {Int i; for (i = 0; i <len; i ) Output [OUTPOS I] = Input [INPOS i];</p> <p>/ * KeyBeantransform is a KeyBean core transform program, with keybeanupdate call, block is a block of original bytes * / private void keybeantransform (Byte Block []) {long a = state [0], b = state [1], c = State [2], D = State [3]; long [] x = new long [16];</p> <p>Decode (X, Block, 64);</p> <p>/ * ROUND 1 * / a = ff (A, B, C, D, X [0], S11, 0xD76AA478L); / * 1 * / d = ff (d, A, b, c, x [1], S12, 0xE8C7B756L); / * 2 * / c = ff (C, D, A, B, X [2], S13, 0x242070dbl); / * 3 * / b = ff (B, C, D, A, X [3], S14, 0XC1BDCEEL); / * 4 * / a = ff (A, B, C, D, X [4], S11, 0xF57c0FAFL); / * 5 * / d = ff (D, A, B , C, X [5], S12, 0x4787C62AL); / * 6 * / c = ff (C, D, A, B, X [6], S13, 0XA8304613L); / * 7 * / b = ff (B , C, D, A, X [7], S14, 0xFD469501L); / * 8 * / a = ff (A, B, C, D, X [8], S11, 0x698098D8L); / * 9 * / d = Ff (D, A, B, C, X [9], S12, 0x8B44F7AFL); / * 10 * / c = ff (C, D, A, B, X [10], S13, 0xFFFF5BB1L); / * 11 * / b = ff (B, C, D, A, X [11], S14, 0x895cd7bel); / * 12 * / a = ff (A, B, C, D, X [12], S11, 0x6b901122L ); / * 13 * / d = ff (D, A, B, C, X [13], S12, 0xFD987193L); / * 14 * / c = ff (C, D, A, B, X [14], S13, 0xA679438EL); / * 15 * / b = ff (B, C, D, A, X [15], S14, 0X49B40821L); / * 16 * /</p> <p>/ * ROUND 2 * / A = GG (A, B, C, D, X [1], S21, 0XF61E2562L); / * 17 * / d = GG (D, A, B, C, X [6], S22, 0XC040B340L); / * 18 * / c = gg (C, D, A, B, X [11], S23, 0X265E5A51L); / * 19 * / b = GG (B, C, D, A, X [0], S24, 0XE9B6C7AAL); / * 20 * / a = gg (A, B, C, D, X [5], S21, 0XD62F105DL); / * 21 * / d = GG (D, A, B , C, X [10], S22, 0x2441453L); / * 22 * ​​/ c = gg (C, D, A, B, X [15], S23, 0XD8A1E681L); / * 23 * / b = GG (B , C, D, A, X [4], S24, 0xE7D3FBC8L); / * 24 * / a = gg (A, B, C, D, X [9], S21, 0X21E1CDE6L); / * 25 * / D = GG (D, A, B, C, X [14], S22, 0XC33707D6L); / * 26 * / c = gg (C, D, A, B, X [3], S23, 0xF4D50D87L); / * 27 * / b = gg (B, C, D, A, X [8], S24, 0X455A14EDL); / * 28 * / a = gg (A, B, C, D, X [13], S21, 0XA9E3E905L ); / * 29 * / d = gg (D, A, B, C, X [2], S22, 0XFCEFA3F8L); / * 30 * / c = GG (C, D, A, B, X [7], S23, 0x676F02D9L); / * 31 * / b = gg (B, C, D, A, X [12], S24, 0x8D2A4C8Al); / * 32 * /</p> <p>/ * ROUND 3 * / A = HH (A, B, C, D, X [5], S31, 0xFFFA3942L); / * 33 * / d = HH (D, A, B, C, X [8], S32, 0x8771F681L); / * 34 * / c = HH (C, D, A, B, X [11], S33, 0x6D9D6122L); / * 35 * / b = HH (B, C, D, A, X [14], S34, 0xFDE5380CL); / * 36 * / a = HH (A, B, C, D, X [1], S31, 0XA4Bee44L); / * 37 * / d = HH (D, A, B , C, X [4], S32, 0X4BDECFA9L); / * 38 * / c = HH (C, D, A, B, X [7], S33, 0xF6BB4B60L); / * 39 * / b = HH (B , C, D, A, X [10], S34, 0XBEBFBC70L); / * 40 * / a = HH (A, B, C, D, X [13], S31, 0x289B7EC6L); / * 41 * / d = HH (D, A, B, C, X [0], S32, 0XEAA127FAL); / * 42 * / c = HH (C, D, A, B, X [3], S33, 0xD4eF3085L); / * 43 * / b = HH (B, C, D, A, X [6], S34, 0x4881D05L); / * 44 * / a = HH (A, B, C, D, X [9], S31, 0XD9D4D039L ); / * 45 * / d = HH (D, A, B, C, X [12], S32, 0xE6DB99E5L); / * 46 * / c = HH (C, D, A, B, X [15], S33, 0x1FA27CF8L); / * 47 * / b = HH (B, C, D, A, X [2], S34, 0XC4AC5665L); / * 48 * /</p> <p>/ * ROUND 4 * / A = II (A, B, C, D, X [0], S41, 0xF429244L); / * 49 * / d = II (D, A, B, C, X [7], S42, 0x432AFF97L); / * 50 * / c = II (C, D, A, B, X [14], S43, 0XAB9423A7L); / * 51 * / b = II (B, C, D, A, X [5], S44, 0XFC93A039L); / * 52 * / a = ii (A, B, C, D, X [12], S41, 0X655B59C3L); / * 53 * / d = II (D, A, B , C, X [3], S42, 0x8F0CCC92L); / * 54 * / c = II (C, D, A, B, X [10], S43, 0xffeff47dl); / * 55 * / b = II (B , C, D, A, X [1], S44, 0x85845DD1L); / * 56 * / a = II (A, B, C, D, X [8], S41, 0x6FA87E4FL); / * 57 * / D = II (D, A, B, C, X [15], S42, 0XFE2CE6E0L); / * 58 * / c = II (C, D, A, B, X [6], S43, 0XA3014314L); / * 59 * / b = II (B, C, D, A, X [13], S44, 0X4E0811A1L); / * 60 * / a = II (A, B, C, D, X [4], S41, 0xF7537E82L ); / * 61 * / d = II (D, A, B, C, X [11], S42, 0xBD3AF235L); / * 62 * / C = II (C, D, A, B, X [2], S43, 0X2AD7D2BBL); / * 63 * / b = II (B, C, D, A, X [9], S44, 0XEB86D391L); / * 64 * / state [0] = a; state [1] = b; state [2] = C; state [3] = D;</p> <p>}</p> <p>/ * Encode disassembles the long array in order, because Java's long type is 64bit, only 32bit, to accommodate the purpose of the original C implementation * / private vid encode (byte [] Output, long [] Input, INT LEN) {INT I, J;</p> <p>For (i = 0, j = 0; j <len; i , j = 4) {OUTPUT [J] = (Byte) (INPUT [i] & 0xffl); OUTPUT [J 1] = (BYTE) (INPUT [I] >>> 8) & 0xffl); OUTPUT [J 2] = (Byte) ((Input [I] >>> 16) & 0xffl); OUTPUT [J 3] = (Byte) (INPUT [I] >>> 24) & 0xffl);}} / * decode synthesizes the Byte array into a long array, because Java's long type is 64bit, only 32bit, high 32bit clear, to adapt Original C Implementation * / Private Void Decode (long [] Output, Byte [] Input, Int Len) {Int i, j;</p> <p>For (i = 0, j = 0; j <len; i , j = 4) OUTPUT [i] = b2iu (input [j]) | (B2IU (Input [J 1]) << 8) | ( B2IU (INPUT [J 2]) << 16) | (B2IU (Input [J 3]) << 24);</p> <p>Return;}</p> <p>/ * B2IU is a "upgraded" program I wrote by the principle that does not consider the principle of the corrective number, because Java has no unsigned operation * / public static long b2iu (byte b) {RETURN B <0? B & 0x7F 128: B;</p> <p>/ * bytehex (), used to convert a BYTE type to a hexadecimal ASCII said that because of the bitte of the Java can't achieve this, we don't have the sprintf in the C language (outbuf, "% 02x ", IB) * / public static string bytehex (byte ib) {char [] Digit = {'0', '1', '2', '3', '4', '5', '6', ' 7 ',' 8 ',' 9 ',' a ',' b ',' c ',' d ',' e ',' f '}; char [] ob = New char [2]; OB [0 ] = DIGIT [(IB >>> 4) & 0x0f]; OB [1] = DIGIT [IB & 0x0F]; String S = New String (OB); Return S;} / * public static void main (String Args ]) {Md5 m = new md5 (); system.out.println ("I love you:" M.getKeyBeanofstr ("I love you"));} * /</p> <p>}</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-38547.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="38547" 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.040</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 = '7dPeyHijp00jN_2FOJiVIOarD7k_2B7AV4EPAS5X2cafXw1JBUSqveYzL5M9zDxV1GQX90pnPfOriZONTfrOFcdhFw_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>