我自己写的一个servlet里面有一段代码老是报异常,编译可以通过,但是一运行就出现异常。为了检查错误,为专门建了一个包含main函数的类,我原封不动的把代码复制到那个main函数中,结果运行一切正常,并没有问题。真是怪事啊,难道相同的代码仅仅挪个地方就会出现问题?又或者代码是在servlet中运行的机制不同。
下面是代码,其中的Web系列类都是第三方类库,不用去深究try
{
WebConversation wc = new WebConversation();
WebRequest r = new PostMethodWebRequest("");
WebResponse re = wc.getResponse(r);
WebTable webTable = re.getTables()[2];
String[][] datas = webTable.asText();
if(datas!=null)
{
MyBean a=new MyBean();
a.setA(datas);
}
} catch (Exception ev) {response.sendRedirect("http://localhost/web/err.html"); return; }
下面是代码,其中的Web系列类都是第三方类库,不用去深究try
{
WebConversation wc = new WebConversation();
WebRequest r = new PostMethodWebRequest("");
WebResponse re = wc.getResponse(r);
WebTable webTable = re.getTables()[2];
String[][] datas = webTable.asText();
if(datas!=null)
{
MyBean a=new MyBean();
a.setA(datas);
}
} catch (Exception ev) {response.sendRedirect("http://localhost/web/err.html"); return; }
解决方案 »
- 使用jdk1.7,但是新语法却不能使用,这是为什么?
- 初学者提问
- 哪个哥们帮我看看``急
- 一个java播放器的问题
- 请教:如何将16进制的String转换为2进制的Binary?
- 有关jdk1.4.0和jdk1.2.2在accessibility方面的冲突:::在线等待加分200
- Applet为什么显示不了?
- 【请问用JAVA作一个下载软件(如FlashGet,网络蚂蚁等)应该怎么设计!!!】
- 杭电 acm 1009题 各位帮忙看看哪里错了 运行没问题啊 提交错误
- java的int数组和char数组在println时的区别
- 如何得到本机系统中相关目录???????????
- 急求 。。。。。哪里有中文的J2SDK1.4.**中文档下载 ?
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.bean.*;
import com.meterware.httpunit.*;
public class ControlServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
try
{
WebConversation wc = new WebConversation();
WebRequest r = new PostMethodWebRequest("http://bbs.tsinghua.edu.cn/bbsodoc.php?board=Song_Visit");
WebResponse re = wc.getResponse(r);
WebTable webTable = re.getTables()[2];
String[][] datas = webTable.asText();
System.out.println(datas[1][3]);
if(datas!=null)
{
MyBean a=new MyBean();
a.setA(datas);
}
} catch (Exception ev) { this.doPost(request,response); }
response.sendRedirect("http://localhost/web/view.jsp");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
this.doPost(request,response);
}
}