導航:首頁 > 源碼編譯 > entityjava源碼

entityjava源碼

發布時間:2022-07-19 18:21:03

1. 如何閱讀Nutz的源碼


開始學習框架思想了,打算先從nutz入手,因為nutz是國人寫的,中文注釋,容易理解

而且nutz框架比較小,但是麻雀雖小五臟俱全,大牛的思想還是可以學到的.

1、

這里if感覺多此一舉,既然這樣判斷何不在warn裡面判斷呢(效率問題),感覺這樣寫法有點蛋疼,


2. 如何用Visual Studio編譯java源代碼

3. java源代碼是給你一個身份證號,通過面板身份證號的輸入,顯示出該身份證主人的出生年月,省份,性別等資料

我當初用struts1和hibernate做了個簡單的!主要的邏輯代碼在下面!資料庫里號碼對應的城市在網上可以查的到
package ;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Expression;

import entity.Shenfenzhen;

public class IdDao {
private static Configuration configuration = new Configuration().configure() ;

private static SessionFactory sessionFactory =configuration.buildSessionFactory();
private static Session session = null;

public Info query(String s){
Info info = null;
StringBuffer stringBuffer = new StringBuffer(s);
if(s.length()==18){
String end = stringBuffer.substring(17);
//System.out.println(end);
if(!end.matches("\\d||x")){
return null;
}

}
else if(s.length()==15){
stringBuffer.insert(6, "19");
stringBuffer.append("3");
}
int i = Integer.parseInt(stringBuffer.substring(0, 6));
//System.out.println(i);
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Shenfenzhen.class);
criteria.add(Expression.eq("num", i));
List<Shenfenzhen> list = criteria.list();
String address = null;
try {
address = list.get(0).getAddress();
}catch (Exception e) {
return null;
}
i = Integer.parseInt(stringBuffer.substring(16,17));
String sex = null;
if(i%2==0){
sex = "女";
}else{
sex = "男";
}
//System.out.println(i);
stringBuffer = new StringBuffer(stringBuffer.substring(6, 14));
// stringBuffer.insert(4, "-");
// stringBuffer.insert(7, "-");
//System.out.println(stringBuffer);
String ss = stringBuffer.toString();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String brithday="";
int year=0;
int month =0;
int day =0;
try {
Date date = dateFormat.parse(ss);
//System.out.println(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH)+1;
day = calendar.get(Calendar.DAY_OF_MONTH);
brithday = (String)(year + "年" + month + "月" + day + "日");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
info = new Info(address, brithday, sex);
Calendar c = Calendar.getInstance();
int nowYear = c.get(Calendar.YEAR);
int nowMonth = c.get(Calendar.MONTH);
int nowDay = c.get(Calendar.DAY_OF_MONTH);

if(nowYear<year){
info = null;
}else if(nowYear ==year && nowMonth<month ){
info = null;
}else if(nowYear == year && nowMonth==month && nowDay<day){
info = null;
}
closeSession(session);
return info;
}

// public static void main(String[] args){
// IdDao = new IdDao();
// .query("342522998711224513");
// System.out.println("x".matches("\\d||x"));
// }
private void closeSession(Session session){
if(session !=null){
session.close();
}
}

}

4. 從文件中讀取數據,保存到一個java一個類中,怎麼實現

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

/**
* 讀出寫出
* @param oldFileName 源文件
* @param newFileName 新文件
* @throws IOException
*/
public static void testRead(String oldFileName,String newFileName) throws IOException{
FileOutputStream fos=new FileOutputStream(new File(newFileName));
RandomAccessFile raf=new RandomAccessFile(new File(oldFileName), "rw");
fos.write(raf.read(new byte[8]));
fos.flush();
fos.close();
raf.close();
}

public static void fileWrite() throws FileNotFoundException, IOException {
testRead("G:/森雲/測試文件1。txt","G:/newFile.txt");
}

5. 用java編寫網路爬蟲,用來爬網路音樂資源,再返回java頁面顯示該怎麼實現

下面是源代碼,希望可以幫到你~~
package com.ly.mainprocess;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class Test1 {
public static void main(String[] args){
Test1 test1 = new Test1();
System.out.println(test1.process("******","******"));
}

@SuppressWarnings("deprecation")
public boolean process(String username,String password) {
boolean ret=false;
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget;
HttpResponse response;
HttpEntity entity;

List<Cookie> cookies;

//組建登錄的post包
HttpPost httppost = new HttpPost("http://login.hi.mop.com/Login.do"); // 用戶登錄
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("nickname", username));
nvps.add(new BasicNameValuePair("password", password));
nvps.add(new BasicNameValuePair("origURL", "http://hi.mop.com/SysHome.do"));
nvps.add(new BasicNameValuePair("loginregFrom", "index"));
nvps.add(new BasicNameValuePair("ss", "10101"));

httppost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
httppost.addHeader("Referer", "http://hi.mop.com/SysHome.do");
httppost.addHeader("Connection", "keep-alive");
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
httppost.addHeader("Origin", "http://hi.mop.com");
httppost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36");
response = httpclient.execute(httppost);
entity = response.getEntity();
// System.out.println("Login form get: " + response.getStatusLine());
EntityUtils.consume(entity);

// System.out.println("Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
// System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
// System.out.println("- " + cookies.get(i).toString());
}
}

//進行頁面跳轉
String url = ""; // 頁面跳轉
Header locationHeader = response.getFirstHeader("Location");
// System.out.println(locationHeader.getValue());
if (locationHeader != null) {
url = locationHeader.getValue(); // 得到跳轉href
HttpGet httpget1 = new HttpGet(url);
response = httpclient.execute(httpget1);
// 登陸成功。。。hoho
}
entity = response.getEntity();
// System.out.println(response.getStatusLine());
if (entity != null) {
// System.out.println("Response content length: " + entity.getContentLength());
}
// 顯示結果
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
// System.out.println(line);
}

//自動打卡
// 訪問網站的子網頁。
HttpPost httppost1 = new HttpPost("http://home.hi.mop.com/ajaxGetContinusLoginAward.do"); // 設置個人信息頁面
httppost1.addHeader("Content-Type", "text/plain;charset=UTF-8");
httppost1.addHeader("Accept", "text/plain, */*");
httppost1.addHeader("X-Requested-With", "XMLHttpRequest");
httppost1.addHeader("Referer", "http://home.hi.mop.com/Home.do");
response = httpclient.execute(httppost1);
entity = response.getEntity();
// System.out.println(response.getStatusLine());
if(response.getStatusLine().toString().indexOf("HTTP/1.1 200 OK")>=0){
ret = true;
}
if (entity != null) {
// System.out.println("Response content length: " + entity.getContentLength());
}
// 顯示結果
reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {

} finally {
httpclient.getConnectionManager().shutdown();
}
return ret;
}
}

6. 給個java與jfreechart畫柱形圖的例子,要源代碼的,我分不多,全給你了

/*java文件*/
package com.cn;

import java.awt.Color;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.io.*;

import javax.servlet.http.HttpSession;

import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.chart.*;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.*;
import org.jfree.chart.servlet.ServletUtilities;

public class BarChartDemo {

/**
* 餅狀圖
*/
public static String generatePieChart(HttpSession session, PrintWriter pw,int w, int h){
String filename = null;
PieDataset dataset = getDataSet();
JFreeChart chart = ChartFactory.createPieChart3D(
"水果產量圖", // 圖表標題
dataset, // 數據集
true, // 是否顯示圖例
false, // 是否生成工具
false // 是否生成URL鏈接
);
chart.setBackgroundPaint(Color.pink);
try {
/*------得到chart的保存路徑----*/
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,session);
/*------使用printWriter將文件寫出----*/
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
return filename;
}

/**
* 柱狀圖
*/
public static String generateBarChart(HttpSession session, PrintWriter pw,int w, int h){
String filename = null;
CategoryDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createBarChart3D(
"水果產量圖", // 圖表標題
"水果", // 目錄軸的顯示標簽
"產量", // 數值軸的顯示標簽
dataset, // 數據集
PlotOrientation.VERTICAL, // 圖表方向:水平、垂直
true, // 是否顯示圖例(對於簡單的柱狀圖必須是false)
false, // 是否生成工具
false // 是否生成URL鏈接
);
try {
/*------得到chart的保存路徑----*/
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,session);
/*------使用printWriter將文件寫出----*/
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
return filename;
}

/**
* 折線圖
*/
public static String generateLineChart(HttpSession session, PrintWriter pw,int w, int h){
String filename = null;
CategoryDataset dataset = getDataSet3();
JFreeChart chart = ChartFactory.createLineChart(
"水果產量圖", // 圖表標題
"水果", // 目錄軸的顯示標簽
"產量", // 數值軸的顯示標簽
dataset, // 數據集
PlotOrientation.VERTICAL, // 圖表方向:水平、垂直
true, // 是否顯示圖例(對於簡單的柱狀圖必須是false)
false, // 是否生成工具
false // 是否生成URL鏈接
);

/*----------設置消除字體的鋸齒渲染(解決中文問題)--------------*/
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

/*------------配置圖表屬性--------------*/
// 1,設置整個圖表背景顏色
chart.setBackgroundPaint(Color.pink);

/*------------設定Plot參數-------------*/
CategoryPlot plot = chart.getCategoryPlot();
// 2,設置詳細圖表的顯示細節部分的背景顏色
//plot.setBackgroundPaint(Color.PINK);
// 3,設置垂直網格線顏色
plot.setDomainGridlinePaint(Color.black);
//4,設置是否顯示垂直網格線
plot.setDomainGridlinesVisible(true);
//5,設置水平網格線顏色
plot.setRangeGridlinePaint(Color.blue);
//6,設置是否顯示水平網格線
plot.setRangeGridlinesVisible(true);

try {
/*------得到chart的保存路徑----*/
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,session);
/*------使用printWriter將文件寫出----*/
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
return filename;
}

/**
* 在本地生成圖片文件
*/
public static void ganarateFruitChart(){
CategoryDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createBarChart3D(
"水果產量圖", // 圖表標題
"月份", // 目錄軸的顯示標簽
"產量(公斤)", // 數值軸的顯示標簽
dataset, // 數據集
PlotOrientation.VERTICAL, // 圖表方向:水平、垂直
true, // 是否顯示圖例(對於簡單的柱狀圖必須是false)
false, // 是否生成工具
false // 是否生成URL鏈接
);

FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("D:\\fruit.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,chart,400,300,null);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fos_jpg.close();
} catch (Exception e) {}
}
}

/**
* 獲取一個餅狀圖的簡單數據集對象
* @return
*/
private static PieDataset getDataSet() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("蘋果", 100);
dataset.setValue("梨子", 200);
dataset.setValue("葡萄", 300);
dataset.setValue("香蕉", 400);
dataset.setValue("荔枝", 500);
return dataset;
}

/**
* 獲取一個柱狀圖數據集對象
* @return
*/
private static CategoryDataset getDataSet2() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "北京", "蘋果");
dataset.addValue(500, "北京", "荔枝");
dataset.addValue(400, "北京", "香蕉");
dataset.addValue(200, "北京", "梨子");
dataset.addValue(300, "北京", "葡萄");
dataset.addValue(500, "上海", "葡萄");
dataset.addValue(600, "上海", "梨子");
dataset.addValue(400, "上海", "香蕉");
dataset.addValue(700, "上海", "蘋果");
dataset.addValue(300, "上海", "荔枝");
dataset.addValue(300, "廣州", "蘋果");
dataset.addValue(200, "廣州", "梨子");
dataset.addValue(500, "廣州", "香蕉");
dataset.addValue(400, "廣州", "葡萄");
dataset.addValue(700, "廣州", "荔枝");
return dataset;
}

/**
* 獲取一個折線圖數據集對象
* @return
*/
private static CategoryDataset getDataSet3() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "北京", "一月");
dataset.addValue(200, "北京", "二月");
dataset.addValue(100, "北京", "三月");
dataset.addValue(400, "北京", "四月");
dataset.addValue(300, "北京", "五月");
dataset.addValue(500, "北京", "六月");
dataset.addValue(90, "北京", "七月");
dataset.addValue(700, "北京", "八月");
dataset.addValue(800, "北京", "九月");
dataset.addValue(1000, "北京", "十月");
dataset.addValue(300, "北京", "十一月");
dataset.addValue(700, "北京", "十二月");
dataset.addValue(1200, "上海", "一月");
dataset.addValue(1100, "上海", "二月");
dataset.addValue(1000, "上海", "三月");
dataset.addValue(900, "上海", "四月");
dataset.addValue(800, "上海", "五月");
dataset.addValue(700, "上海", "六月");
dataset.addValue(600, "上海", "七月");
dataset.addValue(500, "上海", "八月");
dataset.addValue(400, "上海", "九月");
dataset.addValue(300, "上海", "十月");
dataset.addValue(200, "上海", "十一月");
dataset.addValue(100, "上海", "十二月");
dataset.addValue(600, "武漢", "一月");
dataset.addValue(500, "武漢", "二月");
dataset.addValue(400, "武漢", "三月");
dataset.addValue(300, "武漢", "四月");
dataset.addValue(200, "武漢", "五月");
dataset.addValue(100, "武漢", "六月");
dataset.addValue(200, "武漢", "七月");
dataset.addValue(300, "武漢", "八月");
dataset.addValue(400, "武漢", "九月");
dataset.addValue(500, "武漢", "十月");
dataset.addValue(600, "武漢", "十一月");
dataset.addValue(700, "武漢", "十二月");
return dataset;
}

/**
* @param args
*/
public static void main(String[] args) {
ganarateFruitChart();
}
}

/*jsp文件*/
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.io.PrintWriter"%>
<jsp:directive.page import="com.cn.BarChartDemo"/>
<html>
<head>
<title>
</title>
<%
//餅狀圖
String fileNamePie=BarChartDemo.generatePieChart(session,new PrintWriter(out),580,250);
String graphURLPie = request.getContextPath() + "/servlet/DisplayChart?filename=" + fileNamePie;
//餅狀圖
String fileNameBar=BarChartDemo.generateBarChart(session,new PrintWriter(out),580,250);
String graphURLBar = request.getContextPath() + "/servlet/DisplayChart?filename=" + fileNameBar;
//折線圖
String fileNameLine=BarChartDemo.generateLineChart(session,new PrintWriter(out),580,250);
String graphURLLine = request.getContextPath() + "/servlet/DisplayChart?filename=" + fileNameLine;
%>
</head>
<body bgcolor="#ffffff">
<table align="center" width="580" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<img src=" <%= graphURLPie %>"width=580 height=250 border=0 >
</td>
</tr>
<tr>
<td>
<img src=" <%= graphURLBar %>"width=580 height=250 border=0 >
</td>
</tr>
<tr>
<td>
<img src=" <%= graphURLLine %>"width=580 height=250 border=0 >
</td>
</tr>
</table>
</body>
</html>

/*web.xml文件*/
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>DisplayChart </servlet-name>
<servlet-class>
org.jfree.chart.servlet.DisplayChart
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart </servlet-name>
<url-pattern>/servlet/DisplayChart </url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp </welcome-file>
</welcome-file-list>
</web-app>

7. 如何用Visual Studio編譯Java源代碼

打開Visual Studio,建立任意工程。
把工程文件自動生成的Class1.cs等文件刪掉。
向工程文件中增加一個文本文件,命名為Application.java
雙擊Application.java文件編輯java源代碼:
在工程文件中增加一個文本文件,命名為:Compile.bat
Tools -> External Tools...
增加一個entity如下,命名為 Javac
下面,將Compile.bat和Application.java這兩個文件編寫完整:
執行:Tools -> Javac

8. 源碼看的很頭疼,java中的HttpURLConnection類中的,有高人嗎

建議使用httpclient框架,這個比HttpURLConnection好用多了,以下是請求示例:
1. GET 方式傳遞參數

//先將參數放入List,再對參數進行URL編碼
List<BasicNameValuePair> params = new LinkedList<BasicNameValuePair>();
params.add(new BasicNameValuePair("param1", "數據")); //增加參數1
params.add(new BasicNameValuePair("param2", "value2"));//增加參數2
String param = URLEncodedUtils.format(params, "UTF-8");//對參數編碼
String baseUrl = "伺服器介面完整URL";
HttpGet getMethod = new HttpGet(baseUrl + "?" + param);//將URL與參數拼接
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = httpClient.execute(getMethod); //發起GET請求
Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //獲取響應碼
Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8"));//獲取伺服器響應內容
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

2. POST方式 方式傳遞參數
//和GET方式一樣,先將參數放入List
params = new LinkedList<BasicNameValuePair>();
params.add(new BasicNameValuePair("param1", "Post方法"));//增加參數1
params.add(new BasicNameValuePair("param2", "第二個參數"));//增加參數2
try {
HttpPost postMethod = new HttpPost(baseUrl);//創建一個post請求
postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8")); //將參數填入POST Entity中
HttpResponse response = httpClient.execute(postMethod); //執行POST方法
Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //獲取響應碼
Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8")); //獲取響應內容
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

9. "java網路爬蟲怎麼實現抓取登錄後的頁面" 你好,由於最近也急需這個代碼

沒做過網路爬蟲,不過順手寫了個自動登錄貓撲打卡的程序你可以參考一下,需要的包是commons-logging.jar,commons-net-1.4.1.jar,commons-codec-1.3.jar,log4j.jar,httpclient-4.3.1.jar ,下面是源代碼,希望可以幫到你~~
package com.ly.mainprocess;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class Test1 {
public static void main(String[] args){
Test1 test1 = new Test1();
System.out.println(test1.process("******","******"));
}

@SuppressWarnings("deprecation")
public boolean process(String username,String password) {
boolean ret=false;
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget;
HttpResponse response;
HttpEntity entity;

List<Cookie> cookies;

//組建登錄的post包
HttpPost httppost = new HttpPost("http://login.hi.mop.com/Login.do"); // 用戶登錄
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("nickname", username));
nvps.add(new BasicNameValuePair("password", password));
nvps.add(new BasicNameValuePair("origURL", "http://hi.mop.com/SysHome.do"));
nvps.add(new BasicNameValuePair("loginregFrom", "index"));
nvps.add(new BasicNameValuePair("ss", "10101"));

httppost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
httppost.addHeader("Referer", "http://hi.mop.com/SysHome.do");
httppost.addHeader("Connection", "keep-alive");
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
httppost.addHeader("Origin", "http://hi.mop.com");
httppost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36");
response = httpclient.execute(httppost);
entity = response.getEntity();
// System.out.println("Login form get: " + response.getStatusLine());
EntityUtils.consume(entity);

// System.out.println("Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
// System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
// System.out.println("- " + cookies.get(i).toString());
}
}

//進行頁面跳轉
String url = ""; // 頁面跳轉
Header locationHeader = response.getFirstHeader("Location");
// System.out.println(locationHeader.getValue());
if (locationHeader != null) {
url = locationHeader.getValue(); // 得到跳轉href
HttpGet httpget1 = new HttpGet(url);
response = httpclient.execute(httpget1);
// 登陸成功。。。hoho
}
entity = response.getEntity();
// System.out.println(response.getStatusLine());
if (entity != null) {
// System.out.println("Response content length: " + entity.getContentLength());
}
// 顯示結果
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
// System.out.println(line);
}

//自動打卡
// 訪問網站的子網頁。
HttpPost httppost1 = new HttpPost("http://home.hi.mop.com/ajaxGetContinusLoginAward.do"); // 設置個人信息頁面
httppost1.addHeader("Content-Type", "text/plain;charset=UTF-8");
httppost1.addHeader("Accept", "text/plain, */*");
httppost1.addHeader("X-Requested-With", "XMLHttpRequest");
httppost1.addHeader("Referer", "http://home.hi.mop.com/Home.do");
response = httpclient.execute(httppost1);
entity = response.getEntity();
// System.out.println(response.getStatusLine());
if(response.getStatusLine().toString().indexOf("HTTP/1.1 200 OK")>=0){
ret = true;
}
if (entity != null) {
// System.out.println("Response content length: " + entity.getContentLength());
}
// 顯示結果
reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {

} finally {
httpclient.getConnectionManager().shutdown();
}
return ret;
}
}

閱讀全文

與entityjava源碼相關的資料

熱點內容
安卓手機如何進行文件處理 瀏覽:61
mysql執行系統命令 瀏覽:920
php支持curlhttps 瀏覽:133
新預演算法責任 瀏覽:434
伺服器如何處理5萬人同時在線 瀏覽:241
哈夫曼編碼數據壓縮 瀏覽:414
鎖定伺服器是什麼意思 瀏覽:375
場景檢測演算法 瀏覽:607
解壓手機軟體觸屏 瀏覽:338
方舟pv怎麼轉伺服器 瀏覽:99
數據挖掘中誤差值演算法函數 瀏覽:118
php開發套件 瀏覽:190
伺服器的spi板是什麼 瀏覽:896
解壓縮全能王中文密碼是什麼 瀏覽:80
javaftp伺服器上傳文件 瀏覽:103
演算法設計中文版pdf 瀏覽:81
視頻壓縮形式怎麼改 瀏覽:368
perl程序員 瀏覽:789
電子表格對比命令 瀏覽:610
php循環輸出數組內容 瀏覽:750