急急急!!!java.net.ConnectException: 不允许联接

XYM8xym 2011-07-15 01:56:53
程序在我的电脑上运行正确,但将应用程序于被另一个程序调用,部署到Tomcat后启动,点击页面就报的这个错误,那位高手帮我看看。
java.net.ConnectException: 不允许联接
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:231)
at sun.net.www.http.HttpClient.New(HttpClient.java:304)
at sun.net.www.http.HttpClient.New(HttpClient.java:321)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:813)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:765)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:690)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:934)
at java.net.URL.openStream(URL.java:1007)
at com.xml.JW.load(JW.java:112)
at com.xml.JW.getFileDataFromXML(JW.java:42)
at org.apache.jsp.site._1.Transfer_jsp._jspService(Transfer_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(Unknown Source)
at org.apache.jasper.servlet.JspServletWrapper.service(Unknown Source)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.connector.CoyoteAdapter.service(Unknown Source)
at org.apache.coyote.http11.Http11Processor.process(Unknown Source)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Unknown Source)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(Unknown Source)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(Unknown Source)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:595)
...全文
21423 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
XYM8xym 2011-12-27
  • 打赏
  • 举报
回复
谢谢各位,问题解决了,端口错了
wangqm0919 2011-07-15
  • 打赏
  • 举报
回复
1.先单独启动下tomcat,看能否启动
2.看数据库实例是否正确
3.检查配置文件
lin860315 2011-07-15
  • 打赏
  • 举报
回复
高手那个贴是我朋友帮我发的,你要socket部分代码。我没有 我把整个JW.java贴出来吧
package com.xml;

import it.sauronsoftware.base64.Base64;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.entity.AD;
import com.entity.VideoFile;

/**
* 读取VideoXml信息文件内容,解析XML返回VideoList对象
* @author Administrator
*
*/
public class JW {

public List getFileDataFromXML(String filename) throws IOException{

List<VideoFile> filelist = new ArrayList();

System.out.println("JW类中得getFileDataFromXML()参数filename:"+filename);
Document document = load(filename);
NodeList Type = document.getElementsByTagName("Type");
NodeList Url = document.getElementsByTagName("Url");
NodeList StartTime = document.getElementsByTagName("StartTime");
NodeList Duration = document.getElementsByTagName("Duration");
NodeList streamType = document.getElementsByTagName("streamType");
System.out.println("Url.getLength()="+Url.getLength());
for(int i = 0 ; i<Url.getLength();i++)
{

VideoFile videofile = new VideoFile();
videofile.setType(getValueFromNode(Type.item(i)));
videofile.setUrl(Base64.decode(getValueFromNode(Url.item(i))));
videofile.setStartTime(Integer.parseInt(getValueFromNode(StartTime.item(i))));
videofile.setDuration(Integer.parseInt(getValueFromNode(Duration.item(i))));
videofile.setStreamType(getValueFromNode(streamType.item(i)));
filelist.add(videofile);
System.out.println("videofile.toString()="+videofile.toString());
}

System.out.println("filelist.size()="+filelist.size());
return filelist;
}

public List getADDataFromXML(String filename) throws IOException{

List<AD> adlist = new ArrayList();

Document document = load(filename);

NodeList Pos = document.getElementsByTagName("Pos");
NodeList Type = document.getElementsByTagName("Type");
NodeList URL = document.getElementsByTagName("URL");
NodeList Duration = document.getElementsByTagName("Duration");
for(int i = 0 ; i<Pos.getLength();i++)
{
AD ad = new AD();
ad.setPos(Integer.parseInt(getValueFromNode(Pos.item(i))));
ad.setDuration(Integer.parseInt(getValueFromNode(Duration.item(i+1))));
ad.setType(getValueFromNode(Type.item(i+1)));
ad.setURL(Base64.decode(getValueFromNode(URL.item(i))));

adlist.add(ad);
System.out.println("ad.toString()="+ad.toString());
}
return adlist;
}

public String getValueFromNode(Node node){
String value = null;
value = node.getFirstChild().getNodeValue().toString().trim();
System.out.println("JW类中得value:"+value);
return value;
}

public Document load(String filename) throws IOException
{
System.out.println("JW类 load()中得filename="+filename);
Document document = null;
InputStream inStream=null;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();


URL url = new URL(filename);
System.out.println("JW类 url对象为"+url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
System.out.println("JW类 conn对象为"+conn);
inStream = url.openStream();
System.out.println("JW类 inStream对象为"+inStream);

String str = this.replaceEnter(this.inputStream2String(inStream));
System.out.println("JW类 str对象为"+str);
document=builder.parse(this.String2InputStream(str));
document.normalize();
}
catch (Exception ex){
ex.printStackTrace();
System.out.println("JW类 load()抛出了Exception ex异常");
}
finally{
inStream.close();
}

return document;
}

public String inputStream2String(InputStream is)throws IOException
{
BufferedReader in=null;
StringBuffer buffer=null;
try{
in = new BufferedReader(new InputStreamReader(is,"UTF-8"));
buffer = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null){
buffer.append(line);
}
}
catch(Exception ex){
ex.printStackTrace();
System.out.println("JW类 inputStream2String()函数中抛出了异常 ");
}
finally{
in.close();
}
return buffer.toString();
}

public InputStream String2InputStream(String str) throws IOException{
ByteArrayInputStream stream = null;
try {
stream = new ByteArrayInputStream(str.getBytes("UTF-8"));

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
finally{

stream.close();
}

return stream;
}


public String replaceEnter(String string) {
StringBuffer str = new StringBuffer();
String s = string.replace("\r\n", "");
for (int i = 0; i < s.length() ; i++) {
if (s.charAt(i) == '\r'||s.charAt(i) == '\n') {
str.append("");
}else {
str.append(s.charAt(i));
}
}
return (String)str.toString();
}

void writeToFile(String str){
BufferedWriter output;
try {
output = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(this.path()+"zhangshenglin.xml"), "UTF-8"));
;
output.write(str);
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


/**
* @param args
*/
public String path() {
String path =

this.getClass().getProtectionDomain().getCodeSource().getLocation()
.getPath();

if (path.indexOf("WEB-INF") > 0) {

path = path.substring(0, path.indexOf("/WEB-INF/classes") + 1);

return path;

} else {
return "";
}
}


}
Joop_Song 2011-07-15
  • 打赏
  • 举报
回复

连接失败。。

你连接的远程的客户端吗??

IP和端口正确吗?


把你socket部分的代码也贴来看看。。

XYM8xym 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 pipi517 的回复:]
Transfer_jsp是什么内容
[/Quote]

Transfer.jsp

YJ YJ1 = new YJ();
List<Video> list = YJ1.getDataFromXML("http://nk.vodjk.com/RelateArticleService.jsp?VideoID="+VideoID+"&VideoNum="+VideoNum);



JW JW1 = new JW();
List<VideoFile> filelist=JW1.getFileDataFromXML(ADUrl);
List<AD> adlist=JW1.getADDataFromXML(ADUrl);

PrintWriter pout = response.getWriter();


Document document = null;
InputStream inStream=null;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();


URL url = new URL(filename);

inStream = url.openStream();

String str = this.replaceEnter(this.inputStream2String(inStream));
document=builder.parse(this.String2InputStream(str));
document.normalize();
}
catch (Exception ex){
ex.printStackTrace();
}
finally{
inStream.close();
}
凯瑞甘 2011-07-15
  • 打赏
  • 举报
回复
怀疑是IP连接的问题
皮皮 2011-07-15
  • 打赏
  • 举报
回复
Transfer_jsp是什么内容

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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