JSP generates HTML --- PNews

xiaoxiao2021-03-06  59

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.util. *"%> <% @ page import = "java.sql. *"%> <% @ Page Import = "java.io. *"%> <% @ page import = "org.apache.commons.fileUpload. *"%> <% @ page import = "java.text. *"%> <% @ PAGE Import = "javax.servlet. *, javax.servlet.http. *"%> <% //request.setcharacterencoding ("GB2312"); try {string dir = request.getRealPath ("."); DiskfileUpload FU = New DiskfileUpload ); Fu.setsizemax (4194304); // Set the file size. Here the file can only be uploaded within 4m

Fu.setSizTHRESHOLD (4096); // Set buffer size.

Fu.SetRepositoryPath (Dir "/ Ball / news / images"); // Set the temporary directory. List fileItems = fu.parsequest (request); // parsing the request, returns a collection.

Iterator i = fileItems.iterator (); string fieldvalue = ""; string ff = "; string picname =" false "; object tt ="; vector v = new vector (); while (I.hasNext ()) {FileItem Fi = (fileItem) i.next (); if (FI.isformField ()) // This is used to determine if the file properties, {string fieldName = fi.getfieldName (); // Here you get the form of FieldValue = FI.GETSTRING (); // Some of the form value v.addelement (FIELDVALUE);} else // Here you start the external system file {file fullfile = new file (fi.getname ()); ff = fullfile.getname () ; String rr = ""; java.util.Date date2 = new java.util.Date (); SimpleDateFormat formatter = new SimpleDateFormat ( "yyyyMMddHHmmss"); // get time String str2 = formatter.format (date2); StringTokenizer st = New StringTokenizer (ff, "); if (st.hasmoretokens ()) {string test12 = st.nextToken (); rr = st.nextToken (); //system.out.println (RR);} (Rr.Equals ("") &&! r.equals ("gif") &&! rr.equals ("jpg") &&! rr.equals ("jpeg") {picname = "false";} else {Picname = STR2 "." rr; // Take time for image name

File SavedFile = New file (GetServletContext (). GetRealPath ("/ ball / news / images /"), picname); FI.WRITE (SavedFile); // upload to server} //system.out.println("picname- ----------------------- " picname);} //system.out.println ("v ----------- ------------- " v);} String [] flag = {" "," "," "," "," "," "}; // Write data to database Object newtype1 = v.elementat (0); string t = newtype1.tostring (); int newtype = integer.parseint (t); Object; object Rowid1 = v.elementat (string rowid = rowid1.tostring (); object title1 = v.Elementat (2); string title = Title1.toString (); object content1 = v.Elementat (string content = Content1.toString (); // system.out.println (Down); java.util.date date = new java.util.date (); string strdate = date.tolocaString ();

Java.util.date strdate1 = new java.util.date (); string strdate = strdate1.tolocalestring (); // news release time // string newtype = "0"; conn.opendb (); string sql = "SELECT TOP 5 * from b_news where newtype = " newtype " ORDER BY ID DESC "; string straTemp =" related news "; ResultSet RS = conn.executeQuery (SQL); While (rs.next ()) {string t2 = rs.getstring (2); string t4 = rs.getstring (4); strTemp = " "; strTemp = "

String filePath = ""; filePath = request.getRealPath ( "// ball // news // pnews.template"); String templateContent = null; try {templateContent = ReadTemplates.getTlpContent (filePath); System.out.println (templateContent );} Catch (exception e) {system.out.println ("Error to Template!");} // Replace the content in the template //system.out.println ("PICNAME --------- ----------------------- " picname"; TemplateContent = ReplaceAll.replace (TemplateContent, Flag [0], Title); TensLateContent = ReplaceAll.replace templateContent, flag [1], strDate); // templateContent = ReplaceAll.replace (templateContent, flag [2], editer); templateContent = ReplaceAll.replace (templateContent, flag [3], content); templateContent = ReplaceAll.replace ( TemplateContent, Flag [4], Strtemp; TemplateContent = ReplaceallAll.Replace (TemplateContent, Flag [5], Picname);

// According to the time file name and path name Calendar Calendar = Calendar.GetInstance (); string filename = String.Valueof (Calendar.gettimeinmillis ()) ". Html"; string pathname = Request.getRealPath ("ball / news" ) "//" Calendar.get (Calendar.Year) "//" (Calendar.Mont) 1) "//" Calendar.Get (Calendar.day_Of_Month) "/ / "; String Url = Calendar.get (Calendar.Year) " / " (Calendar.Get (Calendar.mont) 1) " / " Calendar.get (Calendar.day_Of_Month) " / "; URL = filename; //system.out.println (URL); Try {Writehtml.save (Templatecontent, Pathname, FileName);} catch (Exception E) {system.out.println ("Error to HTML! ------ ------- " E.getMessage ());


New Post(0)