jsp异常问题...
这是代码部分<%//request.setCharacterEncoding("GBK");%>
<%@ page
contentType="text/html; charset=GBK"
import="
javax.naming.*,
java.util.*,
java.util.zip.*,
java.io.*,
yichuang.http.*,
java.util.regex.Matcher,
java.util.regex.Pattern,
javax.servlet.*,
java.sql.*
"
%>
<jsp:useBean id="DB_INFO" scope="page" class="yichuang.sql.dbSet" type="yichuang.sql.dbSet" />
<jsp:useBean id="Tools" scope="page" class="yichuang.com.Tools"/>
<%DB_INFO.openConn(); %>
<%
int i=0;
try
{ System.out.println("aaaaaaaaa");
String ne_name="";
String createtime="";
String insert_sql="";
String temp="";
String subtemp="";
String url="";
String theContent = "";
String sreach_sql="";
Vector sql_rs=new Vector();
Vector sql_res=new Vector();
Vector names=new Vector();
PageSave thePageSave = new PageSave();
PageSave theSubPageSave = new PageSave();
for(int qq=1;qq<15;qq++){
theContent = thePageSave.getPage("http://zfxxgk.bjxch.gov.cn/XXGKbmxxgk.ycs?inner_id=1426&mulu=5&lastlevel=0&PAGE_NUM_I="+qq);
//out.println("thecontent+++++++"+theContent);
while(theContent.indexOf("<TD style=\"height:22px;width:680px;\">")!=-1){
temp=theContent.substring(theContent.indexOf("<TD style=\"height:22px;width:680px;\">")+37);
ne_name=temp.substring(temp.indexOf("\" target=\"_parent\">")+19);
ne_name=ne_name.substring(0,ne_name.indexOf("</a>"));
//out.println("name+++++"+ne_name+"<br>");
out.println(ne_name+"<br>");
url=temp.substring(0,temp.indexOf("type=5")+6);
url=url.substring(url.indexOf("href")+6);
out.println(url);
createtime=temp.substring(temp.indexOf("<TD style=\"WIDTH: 80px;height:22px;text-align:right\">")+53).trim();
createtime=createtime.substring(0,createtime.indexOf("</TD>")).trim();
//out.println("name+++++"+createtime+"<br>");
out.println(createtime+"<br>");
String theSubContent=theSubPageSave.getPage("http://zfxxgk.bjxch.gov.cn/"+url);
out.println("<br>========================<br>");
//抓取详情内容
subtemp = theSubContent.substring(theSubContent.indexOf("<TD valign = top style = \"width:100%;background-image: url(/f/110819/14FZ/14G0/1716Snap21.jpg);background-repeat:;background-position: ;\"><DIV ID = 'CNT_1003/XXGKqzfgkzn/1519' style ='width:100%;margin-top:3px;margin-left:30px;;margin-right:30px;'>")+248);
subtemp = subtemp.substring(0,subtemp.lastIndexOf("<TD valign = top > </TD>")+54);
//out.println("++++++++++++"+subtemp);
while(temp.indexOf("../")>0){
temp = Tools.replace(temp,"../","",true);
}
//System.out.println(temp);
//theSubContent=subtemp;
//out.println("thecontent+++++++"+theContent);
//out.print("<br /><br />");
try{
sreach_sql="Select ne_id from ne_basic where ne_name=ltrim('"+ne_name+"')";
sql_rs=DB_INFO.getDbsetAll(sreach_sql);
if(!(sql_rs.size()>0))
{
String ne_id=DB_INFO.getNextid("ne_basic","ne_id","10000");
subtemp=Tools.replace(subtemp,"'","\"",true);
subtemp="<center ><SPAN style=\"FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-font-kerning: 0pt; mso-hansi-font-family: 宋体\"><FONT face=Verdana><b>"+ne_name+"</b></font></br></span></BR>"+createtime+"</br></center></br>"+subtemp;
//createtime=Tools.replace(createtime," ","",true);
insert_sql="insert into ne_basic (ne_id,ne_name,ne_info,ne_cl,ne_time) values('"+ne_id+"',ltrim('"+ne_name+"'),'"+subtemp+"</tr></table>','16V716VN16VO',ltrim('"+createtime+"'))";
//out.println(insert_sql);
DB_INFO.execSql(insert_sql);
out.println("<br>ne_id=========="+ne_id+"<br>");
}
// out.println("aa"+subtemp);
theConte
nt=temp;
i++;
out.println("<br>");
out.println(i);
out.println("</br>");
}catch(StringIndexOutOfBoundsException e){
e.printStackTrace();
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
PageSave PageSave = new PageSave();
String hou易做图 = "/XCAJJgzdt";
String biaoshi = "1075";
String YCSDIZHI = "http://ajj.bjxch.gov.cn/XCAJJgzdt.ycs";
String HTNLDIZHI = "http://ajj.bjxch.gov.cn/XCAJJgzdt.html";
theContent = PageSave.getPage(YCSDIZHI+"?kk=1");
String theContent1 = PageSave.getPage(HTNLDIZHI);
String FEN_DIZHI = "";
String SC_DIZHI ="";
String Page_Sql_C = "";
if(((theContent1.length()-theContent.length())>4)||((theContent1.length()-theContent.length())<-4))
{
String ym = hou易做图.substring(hou易做图.lastIndexOf("/")+1);//out.println(ym);
String sql="select page_type from ch_desc where ch_id='"+ym+"'";//
Vector theIfColRS = (Vector)DB_INFO.getDbsetAll(sql);
Vector theIfColReS = (Vector)theIfColRS.elementAt(0);
String page_type = (String)theIfColReS.elementAt(0);
if(page_type.equals("1")){
Page_Sql_C = "insert into new_page_s(page_url,page_path,page_id,exe_state) values('"+YCSDIZHI+"?kk=1','"+biaoshi+hou易做图+".html','"+biaoshi+hou易做图+"','待生成')";
DB_INFO.execSql(Page_Sql_C);
}
if(page_type.equals("2")){
theContent = PageSave.getPage(YCSDIZHI);
if(theContent.indexOf("总<FONT style = \"COLOR:#CC0033\">")!=-1){
int YESHU = Integer
.parseInt(theContent.substring(theContent.indexOf("总<FONT style = \"COLOR:#CC0033\">")+31,theContent.indexOf("</FONT>页")));
for(int h=1; h<=YESHU+1; h++){
if(h==1){
FEN_DIZHI = YCSDIZHI;
SC_DIZHI = hou易做图+".html";
}else{
int w=h-1;
FEN_DIZHI = YCSDIZHI+"?page_num="+w;
SC_DIZHI = hou易做图+"-"+w+".html";
}
Page_Sql_C = "insert into new_page_s(page_url,page_path,page_id,exe_state) VALUES('"+FEN_DIZHI+"','"+biaoshi+SC_DIZHI+"','"+biaoshi+hou易做图+"','待生成')";
DB_INFO.execSql(Page_Sql_C);
}
}else{
Page_Sql_C = "insert into new_page_s(page_url,page_path,page_id,exe_state) values('"+YCSDIZHI+"?kk=1','"+biaoshi+hou易做图+".html','"+biaoshi+hou易做图+"','待生成')";
DB_INFO.execSql(Page_Sql_C);
}
}
}
String o_sql = "insert into new_page_s(page_url,page_path,page_id,exe_state) values('http://ajj.bjxch.gov.cn/XCAJJIndex.ycs','1075/XCAJJIndex.html','1075/XCAJJIndex','待生成')";
DB_INFO.execSql(o_sql);
////////////////////////////////////////////////////////////////////////////////////////////
}
catch (Exception kkfj)
{
kkfj.printStackTrace();
out.println(kkfj);
//System.out.println(kkfj);
}finally{
DB_INFO.closeConn();
out.println(i);
}
%>
点击第一个图片中的列表到第二个图片中,可能出现java.lang.StringIndexOutOfBoundsException: String index out of range: -135 29异常,想要在代码for循环中加while循环,然后加try{}语句,怎么解决 --------------------编程问答-------------------- 数组越界,debug跟一下 --------------------编程问答-------------------- 代码好长。
你这个倒省事,视图、业务、db 操作都放到 jsp 里头去了。
补充:Java , Web 开发