用jsoup解析登录后页面

keensnow 2014-04-03 06:15:19
小弟最近在做Android的一个教务系统,但学校的那个 系统做的比较坑,没有提供接口,所以我只能是用http请求来获得数据。做到现在查询的功能基本上完成了。现在做到选课,但是选课时候的列表是从数据库提取出来的数据。但那个没有找到能达到的url。现在想用jsoup解析下登录成功后的页面,从里面取出要用的数据。
现在问题又来了,学校的那个系统感觉怪怪的,基本流程是服务器验证用户名密码后返回一串XML字符串,格式如下:


<UINF>
<INF>0</INF>
<INF>S13*****</INF>
<INF>姓名^专业班级^入学时间</INF>
<INF>{***}{****}{*****}{N}~***学号***^@1$</INF>
</UINF>

登录页面把这串数据把标签处理完后返回给JSP页面,JSP页面再做分割保存成变量,然后用做其他操作的参数。源代码发送不了,先截几个代码块

function on_Login() { //验证数据的合法性
var ucode=document.getElementById('userCode');
var upwd=document.getElementById('passWord');
var utype;
if (document.getElementById('RadioButtonList1_0').checked) utype=document.getElementById('RadioButtonList1_0');
else if (document.getElementById('RadioButtonList1_1').checked) utype=document.getElementById('RadioButtonList1_1');
else if (document.getElementById('RadioButtonList1_2').checked) utype=document.getElementById('RadioButtonList1_2');
if (ucode.value == "" ) {
if (utype.value='S'){
alert("代码不能为空,请输入学号!");
}
else {alert("代码不能为空,请输入代码!");}
ucode.focus();
return false;
}
if (upwd.value == "") {
alert("密码不能为空,请输入密码!");
upwd.focus();
return false;
}
sendRequest("loginservlet?action=1&ucode="+ucode.value+"&upwd="+upwd.value+"&utype="+utype.value);
return true;
}



function sendRequest(url) {
var timenow = new Date().getTime();
createXMLHttpRequest();
XMLHttpReq.open("GET", url+"&d="+timenow, true);
XMLHttpReq.onreadystatechange = function(){
if (XMLHttpReq.readyState == 4) {
if (XMLHttpReq.status == 200) {
var info=XMLHttpReq.responseXML.getElementsByTagName('INF');
if (info[0].firstChild.data=='0') {
document.getElementById('userID').value=info[1].firstChild.data;
document.getElementById('userInfo').value=info[2].firstChild.data;
document.getElementById('userOther').value=info[3].firstChild.data;
window.onunload=null;
loginForm.submit();
}
else if (info[0].firstChild.data=='1') alert("代码或密码不正确!");
else if (info[0].firstChild.data=='2') alert("你欠学费,暂时不能使用!");
else if (info[0].firstChild.data=='3') alert("您非行政人员,不能使用!");
}
else {
alert("系统故障,请联系管理人员!");
}
}
}
XMLHttpReq.send(null);
}

上面两个函数都是在登录页面的

下面这个是jsp页面上面的一段

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page contentType="text/html; charset=GBK" session="false" isThreadSafe="true"%>
<%@page import="education.util.SysMessage"%>
<%@page import="education.util.TreeOther"%>
<%@page import="education.util.FunctionDeal"%>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Expires","0");
response.setHeader("Pragma","no-cache");
response.setCharacterEncoding("GBK");
request.setCharacterEncoding("GBK");
String userID = (String) request.getParameter("userID");
String userOther = (String) request.getParameter("userOther");
if (userID == null || userOther==null) {
response.sendRedirect("login.html");
return;
}
else {
if (userID.charAt(0) != 'S' && userID.charAt(0) != 'T' && userID.charAt(0) != 'M') {
response.sendRedirect("login.html");
return;
}
}
FunctionDeal fd = new FunctionDeal();
String userInfo[] = fd.splitStr((String) request.getParameter("userInfo"), '^');
String userFile = new String("");
String usertree = new String("");
String userCode = fd.extractWord(1, userOther, '~', '^');
String userright = fd.extractWord(1, userOther, '@', '$');
String dp_sp_id =fd.extractWord(1, userOther, '{', '}');
int uid;
int dpid;
try {
uid = Integer.parseInt(userID.substring(2));
dpid = Integer.parseInt(dp_sp_id);
} catch (Exception e) {
response.sendRedirect("login.html");
return;
}
String dpcode_grade= fd.extractWord(2, userOther, '{', '}');
String fx= fd.extractWord(4, userOther, '{', '}');
userOther= fd.extractWord(3, userOther, '{', '}');
if (userID.charAt(0)=='S'){
usertree = SysMessage.getCourseTreeHtml()+SysMessage.getAddrTreeHtml()+SysMessage.getTPlanTreeHtml();
userFile = "student.html";
}
else {
TreeOther treeOther= new TreeOther();
if (userID.charAt(0)=='T'){
usertree = treeOther.createTeacherCourseMenu(uid).toString()+SysMessage.getTPlanTreeHtml();
userFile = "teacher.html";
}
if (userID.charAt(0)=='M'){
usertree = treeOther.createDepartmentMenu(dpid).toString()+treeOther.createStudentMenu(dpid).toString()+SysMessage.getAddrTreeHtml()+SysMessage.getTPlanTreeHtml();
userFile = "manager.html";
}
treeOther = null;
}
%>



网上说保存下sessionId可以保存会话,但是这样的session,怎么处理啊。
有没有大神帮忙看看,先在这里谢谢了,如果有别的放发能实现麻烦帮忙设计下
再次感谢!!
...全文
431 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_21914959 2014-12-17
  • 打赏
  • 举报
回复
你们学校知道你这么屌吗
keensnow 2014-04-04
  • 打赏
  • 举报
回复
引用 1 楼 huxiweng 的回复:
jsoup本身是可以啊。 你这不是都到登陆成功页面了么
没,只不过时手中有那个网站的源代码 本人小菜,jsoup还不是很会用求解
teemai 2014-04-03
  • 打赏
  • 举报
回复
jsoup本身是可以啊。 你这不是都到登陆成功页面了么

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧