JS Write comments Page

Source: Internet
Author: User
Tags comments json

 js written page can be found on the Internet a lot of articles, in the also for you to introduce a, like friends can refer to the following

The code is as follows: <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "  pageencoding=" Utf-8 "%>  <%  string path = Request.getcontextpath ();  string BasePath = Request.getscheme () + "://"   + request.getservername () + ":" + request.getserverport ()   + path + "/";  %>  <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  <html >  <head>  <meta content= "Width=device-width, initial-scale=1.0, maximum-scale=1.0, User-scalable=no "Name=" viewport ">  <script type=" Text/javascript "src=" Http://ajax.googleapis.com/ajax /libs/jquery/1.5.2/jquery.min.js "></script>  <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 ">  <title> Micro Customer service </title>  <style type=" Text/css ">  body{  text-align:center;  margin:0;  padding:0;  color: #500f60;  background:url (". /images/bj_4.JPG ");  background-repeat:no-repeat;  background-attachment:scroll;  background-size:100% 100%;   Overflow-x: hidden; }  li{  list-style-type:none; }  a:link{  list-style-type: none; }  img{  width:100%; }  #static {  margin:0 auto;  text-align:left;  wid th:90%;  margin-top:20px; }  .aa{  padding-left:16px; }  #bott {  border:3px #5903 solid;  border-radius:6px 6px 6px 6px; -moz-border-radius:6px;  width:90%;  margin-left:5%;&nb Sp }  .tex{  border-top:none;  border-bottom:none;  border-left:none;  border-right:none;   background:fixed; }  </style>  </head>  <script type= "Text/javascript" >  $ (function () {  var row = 5; //Dynamic Add comment   function loadcommentinfo (page) {  $ ("#page"). Text (page);  $.ajax ({  type: "POST", URL: "<%=basepath%>findclickcommentbypage.action",  Data: "page=" +page+ "&row=" +row,  success: function (data) {  var list = data.list;  var row = "";  $ ("#comments"). Empty ();  for (var i = 0; i < list.length; i++) {  row = "<h3><span style=" color: #000; font-size:0.5em; padding-left:70%; " > "+list[i].time+" </span></h3> "+ " <h3 style= "padding-left:12px;" > "+list[i].content+" </h3> ";  if (list[i].repcontent!=null) {  row+=" <h3 style= "Padding-left: 12px; Word-wrap:break-word; Word-break:normal; " > Reply: "+list[i].repcontent+" </h3> "; } " <hr size= "5px;" color= "#f0f" > ";  $ (row). Appendto ($ ("#comments")); }  $ ("#pagetag"). Val (page); } }); };  function Gettotalcontent () {  $.ajax ({  type: "POST",  URL: "<%=basepath%>gettotalnum.action",  Success:function (data) {  $ ("#count"). Text (data.total); if (parseint (data.total) ==0) {  $ ("#page"). Text (0); }  var pagenum = parseint (data.total/row);  $ ( "#totalpage"). Text (parseint (data.total%row==0?pagenum:pagenum+1)); }, }); }  $ ("#submit"). Click (function () {  var content = $ ("#content"). Val ();  if (content== "") {  alert ("Content cannot be empty!");   return; }  $.post ("<%=basepath%>addclickcomment.action", "content=" +content,function (data) {  if (data.success = = True) {  alert ("Publish success!");   $ ("#content"). Val ("");  Loadcommentinfo (parseint ($ ("#pagetag"). Val ());  gettotalcontent ();  } }); });  $ ("#pre"). Click (function () {  var page = parseint ($ ("#pagetag"). Val ());  if (page>1) {  page--;  loadcommentinfo (page); } });  $ ("#next"). Click (function () {  var page = parseint ($ ("#pagetag"). Val ());  if (Page<parseint ($ ("#totalpage"). Text ()) {  page++;  Loadcommentinfo (page); } });  Window.onload = loadcommentinfo (1);  window.onload = Gettotalcontent (); });  </script>   <body>  <input type= "hidden" id= "Pagetag" value= "1" >  <div id= "Static" >  < Div style= "text-align:left; z-index:999 ">  <img src=". /pic/top4.jpg ">  <a href=" <%=basepath%>jsp/index.jsp "><img src=". /pic/fan_2.png "style=" width:10%; Margin-top: -25px; " ></a>  </div>  <button style= "background: #520202; BORDER-TOP:NONE;BORDER:3PX #520202 Solid; border-radius:2px 2px 2px 2px;-moz-border-radius:6px; Color: #FFEA00; "id=" Pre "> Prev </button>  <button style=" background: #520202; BORDER-TOP:NONE;BORDER:3PX #520202 Solid; border-radius:2px 2px 2px 2px;-moz-border-radius:6px;float:right; Color: #FFEA00; "Id=" Next > Next </button>  <p style= "background: #520202; Color: #FFEA00; > <span id= "page" ></span>/<span id= "Totalpage";</span> page </p>  <h1 class= "AA" > Comments (<span id= "Count" ></span>) </h1>  <hr size= "5px;" color= "#590303" >  <div id= "comments" >  </div>  <h2 class= "AA" > Post comments </h2>  <h3 class= "AA" > Your comments:</h3>  <div id= "Bott" >  <textarea rows= "7" Class= "Tex" cols= "100%" id= "content" ></textarea>  </div>  <button style= "margin-left:80" %; BORDER-TOP:NONE;BORDER:3PX #520202 Solid; border-radius:6px 6px 6px 6px;-moz-border-radius:6px; Color: #FFEA00; Background: #520202; id= "Submit" > Release </button>  </div>  </body>  </html>     DAO layer     code as follows: Package dfml.daoimpl;    Import java.sql.sqlexception;  Import java.util.list;    Import javax.annotation.resource;    Import org.hibernate.criteria;  Import org.hibernate.hibernateexception;  Import org.hibernate.query; Import org.hibernate.session;  Import org.hibernate.criterion.order;  Import org.springframework.orm.hibernate3.hibernatecallback;  Import org.springframework.orm.hibernate3.hibernatetemplate;  import org.springframework.stereotype.Component;     Import dfml.dao.clickcommentdao;  import dfml.pojo.clickcomment;    @Component   public class Clickcommentdaoimpl implements clickcommentdao{    private hibernatetemplate hibernatetemplate;     @Resource   public void sethibernatetemplate (Hibernatetemplate hibernatetemplate) {  This.hibernatetemplate = hibernatetemplate; } //Add a comment message   @Override   public boolean Addclickcomment (Clickcomment clickcomment) {  boolean issuccess = false;  try {  hibernatetemplate.save ( clickcomment);  issuccess = true; } catch (Exception e) {  issuccess = false;  e.printstacktrace (); &n Bsp }  return issuccess; } //Paging lookupReview information   @SuppressWarnings ("unchecked")   @Override   public list<clickcomment> Findclickcommentbypage (final int page, final int row) {  list<clickcomment> List = this.hibernatetemplate& nbsp.. executefind (New hibernatecallback<object> () {  @Override   public Object doinhibernate session)   throws Hibernateexception, SQLException {  Criteria c = Session.createcriteria (Clickcomment.class) ;  C.setfirstresult (page-1) * row);  c.setmaxresults (Row);  C.addorder (Order.desc ("Time");  Return c.list (); } });  return list; } //Get comments   @SuppressWarnings ({"Unchecked", " Rawtypes "})   @Override   public Long getclickcommentcount () {  final String hql = ' SELECT count (*) from Cli Ckcomment ";  Long result = null;  result = (long) hibernatetemplate.execute (new Hibernatecallback () {  Pub LIC Object Doinhibernate (session arg0)   throws Hibernateexception, SQLException {  Query query = arg0.createquery (HQL);  return Query.uniqueresult (); } });  return result; } //Update comment information   @Override   public boolean updateclickcomment (Clickcomment clickcomment) {   Boolean issuccess=false;  try {  hibernatetemplate.update (clickcomment);  issuccess=true;   catch (Exception e) {  e.printstacktrace ();  issuccess=false; }  return issuccess; }& nbsp Find comment information based on ID   @Override   public clickcomment findclickcommentbyid (int id) {  return (clickcomment) Hibernatetemplate.find ("from clickcomment where id =?",  IDs). Get (0); } //Delete comment   @Override   public boolean deleteclickcomment (Clickcomment clickcomment) {  boolean issuccess=false;  try {  Hibernatetemplate.delete (clickcomment);  issuccess=true; } catch (Exception e) {  e.printstacktrace () ;  issuccess=false; }  return issuccess; } //Query All comments   @SuppressWarnings ("unchecked")   @Override   public list<clickcomment> Findallclickcomment () {  return Hibernatetemplate.find ("from Clickcomment"); }   }    Struts configuration     code is as follows: <package name= "clickcomment" extends= "Json-default" namespace= "/" >  <action Name= "Addclickcomment" method= "addclickcomment" class= "clickcommentaction" >  <result name= "Add" type= " JSON ">  <param name=" root ">map</param>  </result>  </action>  < Action name= "Findclickcommentbypage" method= "Findclickcommentbypage" class= "Clickcommentaction" >  < Result name= "Findbypage" type= "JSON" >  <param name= "root" >map</param>  </result>   </action>  <action name= "Gettotalnum" method= "Gettotalnum" class= "Clickcommentaction" >   <result name= "Total" type= "json" >  <param name= "root" >map</param>&nbsP </result>  </action>  <action name= "updateclickcomment" method= "Updateclickcomment" class= "Clickcommentaction" >  <result name= "Update" type= "JSON" >  <param name= "root" >map</ param>  </result>  </action>  <action name= "findallclickcomment" method= " Findallclickcomment "class=" clickcommentaction ">  <result name=" list "type=" JSON ">  <param Name= "root" >map</param>  </result>  </action>  <action name= " Deleteclickcomment "method=" deleteclickcomment "class=" clickcommentaction ">  <result name=" Delete "type= "JSON" >  <param name= "root" >map</param>  </result>  </action>    action    Code as follows: Package dfml.action;    Import java.sql.date;  Import java.text.simpledateformat;  Import java.util.hashmap;  import java.util.list;  import Java.util.Map;   &NBSp Import javax.annotation.resource;    Import org.springframework.context.annotation.scope;  Import org.springframework.stereotype.component;    Import com.opensymphony.xwork2.actionsupport;    Import dfml.dao.clickcommentdao;  Import dfml.pojo.activity;  import dfml.pojo.clickcomment;    @ Component ("Clickcommentaction")   @Scope ("prototype")   public class Clickcommentaction extends actionsupport{    private static final long Serialversionuid = 1l;    Private Clickcommentdao clickcom mentdao;  private map<string, object> map;  private string content;//comment content   private string Repconten t;//reply comment   private int page;  private int row;  private int rows;  private int id;  public void s Etid (int id) {  this.id = id; }  public map<string, object> Getmap () {  return map; }&nbs P @Resource   public void Setclickcommentdao (clickcommenTdao Clickcommentdao) {  This.clickcommentdao = clickcommentdao; }  public void SetContent (String Content) {  this.content = content; }  public void setrepcontent (String repcontent) {  This.repconte NT = repcontent; }  public void setpage (int page) {  this.page = page; }  public void Setrow (in T row) {  This.row = row; }  public void setrows (int rows) {  this.rows = rows; } //Add comments For micro-user   public String addclickcomment () {  boolean issuccess = false;  map = new hashmap<string, object& gt; ();  clickcomment clickcomment = new Clickcomment ();  simpledateformat format = new SimpleDateFormat (" Yyyy-mm-dd HH:mm:ss ");  Clickcomment.settime (Format.format (New Date (System.currenttimemillis)));  Clickcomment.setcontent (content);  try {  issuccess = clickcommentdao.addclickcomment (clickComment);   catch (Exception e) {  issuccess = false;  E.Printstacktrace (); }  map.put ("Success", issuccess);  return "Add"; } //pagination Find comments User Micro User   Public String findclickcommentbypage () {  map = new hashmap<string, object> ();  map.put ("list", cl Ickcommentdao.findclickcommentbypage (page, row));  return "Findbypage"; } //Query comment number for micro-user   Public String Gettotalnum () {  map = new hashmap<string, object> ();  map.put ("Total", Clickcommentdao.getclickcommentcount ());  return "Total"; } //reply comments for admin   public String Updateclickcomment () {  boolean issuccess=false;  map=new hashmap<string, object> ();  Clickcomment clickcomment =clickcommentdao.findclickcommentbyid (ID);  if (clickcomment!=null) {  Clickcomment.setrepcontent (repcontent);  issuccess=clickcommentdao.updateclickcomment (clickComment);  }  map.put ("Success", issuccess);  return "Update"; } //Query All comments for admin   public String FindalLclickcomment () {  map=new hashmap<string, object> ();  list<clickcomment> lists= Clickcommentdao.findclickcommentbypage (page, rows);  list<clickcomment> listss= Clickcommentdao.findallclickcomment ();  map.put ("Rows", lists);  map.put ("Total", listss.size ());  Map.put ("list", LISTSS);  return "list"; } //delete comments for admin   public String deleteclickcomment () {   Boolean issuccess=false;  map=new hashmap<string, object> ();  clickcomment = Clickcommentdao.findclickcommentbyid (ID);  if (clickcomment!=null) {  issuccess= Clickcommentdao.deleteclickcomment (clickcomment); }  map.put ("Success", issuccess);  return "Delete "; }     }    pojo    code as follows: Package dfml.pojo;    Import java.io.Serial izable;  Import javax.persistence.entity;  Import javax.persistence.generatedvalue;  Import javax.persistence.id;   //Comments Table   @Entity   public class Clickcomment implements serializable{      private static final long Serialversionuid = 1l;  Private Integer id;  private string time;//comment time   private string content;//comment content &nb Sp private string name;//reviewer   private string repcontent;//reply comment         @Id   @GeneratedValue &NB Sp Public Integer getId () {  return id; }    public void setId (Integer id) {  this.id = id; }   public string getrepcontent () {  return repcontent; }  public void setrepcontent (string repcontent {  this.repcontent = repcontent; }  public String getTime () {  return time; }  public vo ID settime (String time) {  this.time = time; }  public String getcontent () {  return content; }     public void setcontent (String content) {  this.content = content; }    public String ge Tname () {  reTurn name; }    public void SetName (String name) {  this.name = name; } }   
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.