当前位置: 代码迷 >> Java Web开发 >> 处置页面重定向
  详细解决方案

处置页面重定向

热度:59   发布时间:2016-04-12 22:26:14.0
处理页面重定向
我用httpclient登录后,返回一个流。处理流后应该怎么重定向到我想要的查看设备的页面上去,页面怎么返回他的XML。。急求处理过程。。我先贴上代码。在线等
这个是http处理
package org.cl.impl;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.cl.vo.Tuser;

public class ITuserImpl {

public static Tuser login(String logonName,String password) throws URISyntaxException {
String url="http://host:port/web_xml_interface/user_logon.xml?" +
"logonName="+logonName+"&password="+password+"&" + 
"platformId=010006&logonType=2&Ver=sdk_001" ;
HttpClient httpclient = new DefaultHttpClient();
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("logonName", logonName));
qparams.add(new BasicNameValuePair("password", password));
//HttpPost post = new HttpPost("url");
Tuser requestUser = new Tuser();
requestUser.setlogonName(logonName);
requestUser.setPassword(password);
URI uri = URIUtils.createURI("http","host:port",-1,"/web_xml_interface/user_logon.xml",
    URLEncodedUtils.format(qparams, "UTF-8"), null);
HttpGet httpget =new HttpGet(url);

InputStream stream = null;
try{ 
      //HttpResponse status = httpclient.execute(post);
  HttpResponse response = httpclient.execute(httpget);
  stream = response.getEntity().getContent(); 
  if(stream != null){
  BufferedReader reader=new BufferedReader(new InputStreamReader(stream));
  String htmlRet=""; 
  String tmp = null;
  while((tmp=reader.readLine())!=null){
  htmlRet+=tmp+"\r\n";
}
 System.out.println(new String(htmlRet.getBytes("ISO-8859-1"),"GBK"));  
 stream.close(); 
  }
        }catch (IOException e) {
         e.printStackTrace();
  相关解决方案