a common jsp

來源:互聯網
上載者:User
<%@ page contentType="text/html; charset=gb2312" %><%@ page language="java" import="java.sql.*,javax.servlet.*,javax.servlet.http.*,java.util.*,java.net.*,java.io.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'OpposiveSendXml.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">  
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
  
  <body>
  Send Xml to Server <br>
  <%!
  public String SendXml(String strPostUrl,String strXml,int nReadTimeOut ) throws Exception
 {
 URL url = new URL(strPostUrl);
 URLConnection connection = url.openConnection();
 HttpURLConnection httpConn = (HttpURLConnection) connection; 
 OutputStream out = null;
 String strTempRecXml = "";
 DataInputStream dis = null; 
 try
 {
 byte[] b = strXml.getBytes();
 httpConn.setConnectTimeout(10000);
 httpConn.setReadTimeout(nReadTimeOut);
 httpConn.setRequestProperty( "Content-Length",String.valueOf( b.length ) );
 httpConn.setRequestProperty("Content-Type","text/xml; charset=gbk");
 httpConn.setRequestMethod( "POST" );
 httpConn.setDoOutput(true);
 httpConn.setDoInput(true); 
 out = httpConn.getOutputStream();
 out.write( b ); 
 out.close();
 byte bRecByte[] = new byte[1025];
 dis = new DataInputStream(httpConn.getInputStream());
 BufferedInputStream bis= new BufferedInputStream(dis); 
 int nByte = -1;
 ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
 nByte = bis.read(bRecByte,0,1024);
 while( nByte != -1 )
 {
 baoStream.write(bRecByte,0,nByte);
 nByte = bis.read(bRecByte,0,1024);
 }
 byte abyte[] = baoStream.toByteArray();
 strTempRecXml = new String(abyte,"GBK");
 strTempRecXml = strTempRecXml.replaceAll("&lt;","<");
 strTempRecXml = strTempRecXml.replaceAll("&gt;",">");
 }
 catch(Exception e)
 {
 System.out.println("發送POST請求出現異常!" + e);
 e.printStackTrace();
 }
 //使用finally塊來關閉輸入資料流
 finally
 {
 try
 {
 if (out != null)
 {
 out.close();
 out = null;
 }
 if (dis != null)
 {
 dis.close();
 dis = null;
 }
 if (httpConn != null)
 {
 httpConn.disconnect();
 httpConn = null;
 }
 }
 catch (IOException ex)
 {
 ex.printStackTrace();
 }
 }
 return strTempRecXml;
 } 
   
  %>
   
  <form name="frm" action="testBossResponse.jsp" method="post">
  <center>URL<input type="text" name="url" style="width: 150px"/>
  <br/>
  時間:<input type="text" name="time" style="width: 164px"/>
  <br/>
  <textarea name="testxml" rows="20" cols="50"></textarea>
  <br/>
  <input type="hidden" name="subTag" value="">
  <input type="submit" value="提交" onclick="javascript:document.frm.subTag.value='sub'">
 </center>  
  </form>
   
  <%
  String subtag = request.getParameter("subTag")==null?"":request.getParameter("subTag");
  String msg = "";
  if(subtag.equals("sub")){
  String rs_url = request.getParameter("url");
  String rs_time = request.getParameter("time");
  String rs_value = request.getParameter("testxml");
  msg = SendXml(rs_url,rs_value,Integer.parseInt(rs_time));
  if(msg.length()>0)
  {
  out.println("結果\n:"+msg);
  out.println("發送類比的賬戶資訊\n");
  SendXml("http://localhost:8090/MobileAd/MainServers","<operation_out>"
  +"<service_name>pcs_mobileadvertise_agent_information</service_name>"
  +"<request_type>1001</request_type>"
  +"<sysfunc_id>93001001</sysfunc_id>"
  +"<request_seq>100000031186</request_seq>"
  +"<response_time>20091013113712</response_time>"
  +"<response_seq>101313103</response_seq>"
  +"<request_source>201015</request_source>"
  +"<response>"
  +"<start_time>0</start_time>"
  +"<brand_id>1012</brand_id>"
  +"<total_amount>20</total_amount>"
  +"</response>"
  +"<content/>"
+"</operation_out>",10000);
  }
  else
  {
  out.println("結果\n:"+"無返回結果");
  }
  }
   
   
   
   
  %>
   
   
   
  </body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.