导航:首页 > 源码编译 > 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源码相关的资料

热点内容
喷油螺杆制冷压缩机 浏览:577
python员工信息登记表 浏览:375
高中美术pdf 浏览:158
java实现排列 浏览:511
javavector的用法 浏览:979
osi实现加密的三层 浏览:230
大众宝来原厂中控如何安装app 浏览:911
linux内核根文件系统 浏览:240
3d的命令面板不见了 浏览:521
武汉理工大学服务器ip地址 浏览:144
亚马逊云服务器登录 浏览:521
安卓手机如何进行文件处理 浏览:69
mysql执行系统命令 浏览:926
php支持curlhttps 浏览:142
新预算法责任 浏览:443
服务器如何处理5万人同时在线 浏览:247
哈夫曼编码数据压缩 浏览:424
锁定服务器是什么意思 浏览:383
场景检测算法 浏览:616
解压手机软件触屏 浏览:348