网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Struts2中json插件如何使用

今天就跟大家聊聊有关Struts2 中json插件如何使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

成都创新互联公司:从2013年成立为各行业开拓出企业自己的“网站建设”服务,为近1000家公司企业提供了专业的成都做网站、成都网站建设、成都外贸网站建设、网页设计和网站推广服务, 按需定制由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。

***步:在struts2基本jar包的基础上添加struts2-jsonplugin

第二步:在stuts.xml文件中将extends由默认的struts-default改为json-default

第三步:在jsp中引入jquery

第四步:画页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  <%      String path = request.getContextPath();      String basePath = request.getScheme() + "://"             + request.getServerName() + ":" + request.getServerPort()              + path + "/";  %>                    新闻公告                                         jQuery(document).ready(function()         {                  $("#mes_button").bind("click",function(event){                                    var m_name = $("#m_name").val();                  var m_content = $("#m_content").val();                  var b_id = $("#b_id").val();                  $.ajax({                      type: "POST",                      url: "addMessage.action",                      data:{"m_name":m_name,"m_content":m_content,"b_id":b_id} ,                      success: function (data) {                                 $("#message_list").append(""   + data.m_name + "

" + data.m_content +"

");                      }                  });                             });                           });                                                                                                                      
                                                                    首页                              
                                                                 新闻公告                                                                                               专业动态                                                                                               文章列表                                                                                               成果展示                                                                                                下载中心                                                                                               管理员入口                                                                                                                                                 正文                                                                                                

                              ${ins.b_title }                          

                                                        时间:${ins.b_date }                                                                                  ${ins.b_content}                                                                                                                                                                                                                                                                         发表评论                                                                                  用户名:                                                                                                                                                                                                                                                                                                                                                                                                      
                  
              
                                                 Copyright (c) 2012 Inc All rights reserved 版权所有 by                  黑龙江科技学院                                                                      

第四步:写业务代码

public void addMessage(int b_id,String m_content,String m_name)      {          PreparedStatement ps = null;          try         {              String sql = "insert into message(b_id,m_name,m_content,m_date,m_status) values(?,?,?,?,?)";               ps = DBUtils.getConnection().prepareStatement(sql);              ps.setInt(1,b_id);              ps.setString(2,m_content);              ps.setString(3,m_name );              ps.setDate(4, new Date(new java.util.Date().getTime()));              ps.setString(5, "1");              ps.executeUpdate();          }          catch (Exception e)          {              e.printStackTrace();          }          finally         {              DBUtils.close(ps);              DBUtils.close();          }                }

第五步:在action调用该方法:目的是将留言录入数据库

package com.ele.web.action.message;   import java.io.BufferedInputStream;  import java.io.BufferedOutputStream;  import java.io.File;  import java.io.FileInputStream;  import java.io.FileOutputStream;  import java.io.IOException;  import java.io.InputStream;  import java.io.OutputStream;  import java.io.PrintWriter;  import java.text.DateFormat;  import java.text.SimpleDateFormat;  import java.sql.Date;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse;   import org.apache.struts2.ServletActionContext;   import com.ele.services.MessageServices;  import com.ele.services.NewsServices;  import com.ele.vo.Ele_messageVO;  import com.ele.vo.Ele_newsVO;  import com.opensymphony.xwork2.ActionContext;  import com.opensymphony.xwork2.ActionSupport;   public class AddMessageAction extends ActionSupport  {      private String m_name;            private String m_content;            private int b_id;            public int getB_id()      {          return b_id;      }       public void setB_id(int bId)      {          b_id = bId;      }       public String getM_name()      {          return m_name;      }       public void setM_name(String mName)      {          m_name = mName;      }       public String getM_content()      {          return m_content;      }       public void setM_content(String mContent)      {          m_content = mContent;      }            @Override     public String execute()      {           MessageServices msgServices = new MessageServices();          msgServices.addMessage(b_id, m_content, m_name);                  return SUCCESS;      }        }

看完上述内容,你们对Struts2 中json插件如何使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


网页名称:Struts2中json插件如何使用
网页URL:http://bjjierui.cn/article/ijdeji.html