post与get的区别

1)get用于信息获取,post用于更新资源。

2)get数据放在请求行中,post数据放在请求体内。

3)get对数据长度有限制(2083字节),post没有限制。

4)post比get安全性高。

Netty Http+Xml协议栈开发

高效的XML绑定JiBx     JOPO <=> XML

package com.netty.ch10;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;

import com.netty.ch10.httpXML.pojo.Order;
import com.netty.ch10.httpXML.pojo.OrderFactory;

/**
 * jiBx类库的使用
 * @author Administrator
 * ANT 脚本生成XML与对象的绑定关系
 *1)下载JiBx包  
 *2)JiBx包  的example下找到一个build.xml  并运行target  ==>  BindGen  生成 binding.xml 和 pojo.xsd
 *  <target name="bindgen">
  
    <echo message="Running BindGen tool"/>
    <java classpathref="classpath" fork="true" failonerror="true"
        classname="org.jibx.binding.generator.BindGen">
      <arg value="-s"/>
      <arg value="${basedir}/src/com/netty/ch10/httpXML/pojo"/>
      <arg value="com.netty.ch10.httpXML.pojo.Order"/>
    </java>
    
  </target>
  3)jibx编译命令   动态修改POJO类    ==>   bind
   <!-- bind as a separate step -->
  <target name="bind" depends="check-binding">
    
    <echo message="Running JiBX binding compiler"/>
    <taskdef name="bind" classname="org.jibx.binding.ant.CompileTask">
      <classpath>
        <fileset dir="${jibx-home}/lib" includes="*.jar"/>
      </classpath>
    </taskdef>
    <bind binding="${basedir}/binding.xml">
      <classpath ref/>
    </bind>
    
  </target>
  4)运行测试类
 */
public class TestOrder {
    

    private IBindingFactory factory = null;
    private StringWriter write = null;
    private StringReader reader = null;
    private final static String CHARSET_NAME = "UTF-8"; 
    
    /**
     * pojo to xml
     * @param order
     * @return
     * @throws JiBXException
     * @throws IOException
     */
    private String encode2Xml(Order order) throws JiBXException, IOException{
        factory = BindingDirectory.getFactory(Order.class);
        write = new StringWriter();
        IMarshallingContext mctx = factory.createMarshallingContext();
        mctx.setIndent(2);
        mctx.marshalDocument(order,CHARSET_NAME,null,write);
        String xmlStr = write.toString();
        write.close();
        System.out.println(xmlStr);
        return xmlStr;
    }
    
    private Order decode2Order(String xmlBody) throws JiBXException{
        reader = new StringReader(xmlBody);
        IUnmarshallingContext uctx = factory.createUnmarshallingContext();
        Order order = (Order)uctx.unmarshalDocument(reader);
        return order;
        
    }
    public static void main(String[] args) throws JiBXException, IOException {
        TestOrder test = new TestOrder();
        Order order = OrderFactory.create();
        String body = test.encode2Xml(order);
        Order order2 = test.decode2Order(body);
        System.out.println(order2);
    }
    
}
View Code

相关文章: