PaServlet.java
资源名称:MY_PAPA.rar [点击查看]
上传用户:xie_wn
上传日期:2022-03-04
资源大小:941k
文件大小:5k
源码类别:
网络截获/分析
开发平台:
Java
- package com.servlet;
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.commons.httpclient.NameValuePair;
- import au.id.jericho.lib.html.Segment;
- import au.id.jericho.lib.html.Source;
- import com.util.ClientUtil;
- import com.util.HtmlUtil;
- /**
- * Servlet implementation class PaServlet
- */
- public class PaServlet extends HttpServlet {
- String zhi;
- protected void service(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // TODO Auto-generated method stub
- request.setCharacterEncoding("GBK");
- String sj=request.getParameter("sj");
- zhi=request.getParameter("zhi");
- System.out.println(zhi);
- if("".equals(sj) || "".equals(zhi))
- {
- response.sendRedirect(request.getContextPath()+"/jsp") ;
- }
- else if("ip".equals(sj))
- {
- ipSend(request,response);
- }
- else if("sjj".equals(sj))
- {
- sjSend(request,response);
- }
- else if("sf".equals(sj))
- {
- sfSend(request,response);
- }
- else if("ss".equals(sj))
- {
- ssSend(request,response);
- }
- }
- protected void ipSend(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // TODO Auto-generated method stub
- String url="http://www.ip138.com/ips.asp";
- NameValuePair nvp1=new NameValuePair("action","2");
- NameValuePair nvp2=new NameValuePair("ip",zhi);
- NameValuePair[] aa=new NameValuePair[]{nvp1,nvp2};
- ClientUtil cu=new ClientUtil();
- Source s=new Source(cu.post(url, aa));
- //System.out.println(s.toString());
- Segment sg=HtmlUtil.getSegment("table", 2, s);
- // System.out.println(sg.toString());
- Segment td=HtmlUtil.getSegment2("td", 2, sg);
- Segment ul=HtmlUtil.getSegment2("ul", 0, td);
- request.setAttribute("ip", zhi);
- request.setAttribute("nr", ul.toString());
- request.getRequestDispatcher("/jsp/ip.jsp").forward(request, response);
- }
- protected void sjSend(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // TODO Auto-generated method stub
- String url="http://www.ip138.com:8080/search.asp";
- NameValuePair nvp1=new NameValuePair("action","mobile");
- NameValuePair nvp2=new NameValuePair("mobile",zhi);
- NameValuePair[] aa=new NameValuePair[]{nvp1,nvp2};
- ClientUtil cu=new ClientUtil();
- Source s=new Source(cu.post(url, aa));
- System.out.println(s.toString());
- Segment sg=HtmlUtil.getSegment("table", 1, s);
- //归属地 gsd 卡类型 klx
- String gsd=HtmlUtil.getSegment2("td",4, sg).extractText();
- String klx=HtmlUtil.getSegment2("td",6, sg).extractText();
- String qh=HtmlUtil.getSegment2("td",8, sg).extractText();
- String yb=HtmlUtil.getSegment2("td",10, sg).extractText();
- yb=yb.split(" ")[0];
- request.setAttribute("sj", zhi);
- request.setAttribute("gsd", gsd);
- request.setAttribute("klx", klx);
- request.setAttribute("qh", qh);
- request.setAttribute("yb", yb);
- request.getRequestDispatcher("/jsp/sj.jsp").forward(request, response);
- }
- protected void sfSend(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // TODO Auto-generated method stub
- String sf=request.getParameter("sf");
- String url="http://qq.ip138.com/idsearch/index.asp";
- NameValuePair nvp1=new NameValuePair("action","idcard");
- NameValuePair nvp2=new NameValuePair("userid","230105198306031915");
- NameValuePair[] aa=new NameValuePair[]{nvp1,nvp2};
- ClientUtil cu=new ClientUtil();
- Source s=new Source(cu.post(url, aa));
- Segment sg=HtmlUtil.getSegment("table", 4, s);
- //性别 出生日期 发证地 现为
- String xb=HtmlUtil.getSegment2("td",1, sg).extractText();
- String csrq=HtmlUtil.getSegment2("td",3, sg).extractText();
- String fzd=HtmlUtil.getSegment2("td",5, sg).extractText();
- String xw=HtmlUtil.getSegment2("td",7, sg).extractText();
- request.setAttribute("xb", xb);
- request.setAttribute("csrq", csrq);
- request.setAttribute("xw", xw);
- request.setAttribute("fzd", fzd);
- request.getRequestDispatcher("/jsp/sf.jsp").forward(request, response);
- }
- protected void ssSend(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // TODO Auto-generated method stub
- }
- }