struts与datagrid显示数据-创新互联

一、创建Web工程
   工程名称:sajdemo
二、添加jar包支持
   --struts-2.8.7.jar
   commons-fileupload-1.2.2.jar
   commons-io-2.0.1.jar
   commons-lang3-3.1.jar
   freemarker-2.3.19.jar
   struts2-core-2.3.7.jar
   ognl-3.0.5.jar
   xwork-core-2.3.7.jar
   javassist-3.11.0.GA.jar
   --json.jar   
   json-lib-2.3-jdk15.jar
   struts2-json-plugin-2.3.7.jar
   commons-lang-2.4.jar
   ezmorph-1.0.6.jar
   commons-beanutils-1.8.0.jar
三、添加配置文件与修改web.xml文件
   web.xml配置
   
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      
         struts2
         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      

      
         struts2
         /*
      

      
         index.jsp
      

   

   struts.xml配置
   
         "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
      "http://struts.apache.org/dtds/struts-2.3.dtd">
   
   
      
      
         
            
               result
            

         

      

   

四、创建Action与javabean
   1.在src下创建包
      包名:cn.jbit.sajdemo.domain
      包名:cn.jbit.sajdemo.web.action
   2.在包下创建Action与javabean
      javabean:
      public class Product {
         private String productId;
         private String productName;
         private Double productPrice;
         //省略get and set
      }
      
      public class OrderItem {
         private String itemId;
         private Integer count;
         private Product product;
         //省略get and set
      }
      
      public class OrderItemAction extends ActionSupport {
         private JSONObject result;
         public String list(){
            //创建产品
            Product p1 = new Product();
            p1.setProductId("p123");
            p1.setProductName("苹果手机");
            p1.setProductPrice(3000d);
            
            Product p2 = new Product();
            p2.setProductId("p124");
            p2.setProductName("三星手机");
            p2.setProductPrice(3000d);
            //创建订单项
            OrderItem oi1 = new OrderItem();
            oi1.setCount(10);
            oi1.setItemId("o123");
            oi1.setProduct(p1);
            
            OrderItem oi2 = new OrderItem();
            oi2.setCount(20);
            oi2.setItemId("o124");
            oi2.setProduct(p2);
            
            
            //创建集合并添加订单项
            List orderItems = new ArrayList();
            orderItems.add(oi1);
            orderItems.add(oi2);
            
            
            //将集合添加到Map中
            Map map = new HashMap();
            map.put("rows", orderItems);
            
            
            //将Map转换为Json格式
            result = JSONObject.fromObject(map);
            
            //输出Json后的格式数据
            System.out.println(result);
            return SUCCESS;
         }
         //省略get and set
      }
五、添加EasyUI支持
   jquery-easyui-1.3.2
六、视图
   <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
   <%
   String path = request.getContextPath();
   String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
   %>
   
   
    
      
      My JSP 'index.jsp' starting page
      
      
         
      
      
       
      
      
        
   
    
      

 
    
    
   
   struts与datagrid显示数据

创新互联主营赣县网站建设的网络公司,主营网站建设方案,app软件定制开发,赣县h5重庆小程序开发公司搭建,赣县网站营销推广欢迎赣县等地区企业咨询

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:struts与datagrid显示数据-创新互联
本文URL:http://pwwzsj.com/article/hoogj.html