我在jsp / servlet中创建了简单的Web应用程序。
登录后,想要通过TCP / IP建立到远程服务器的套接字通信[IP和端口可用]
我创建了正在进行套接字通信的类的jar文件。
当我在servlet中使用jar文件时,我得到异常
Feb 10, 2016 3:28:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.Temp.ServerServlet] in context with path [/Temp_Hosting] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: TCPClient/TCPClient
at com.temp.ServerServlet.doPost(ServerServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

但是,当我使用构建jar的相同类文件时,它完全正常。
所以在servlet中,调用下面正在进行套接字通信的类的方法工作正常。
以下是方法定义是类
public String initializeServer(String _ipAddress, int portNo){
String msg = "Failure";
BufferedReader br = null;
BufferedOutputStream bos = null;
byte buffer[] = null;
String send;
try {
Socket socket = new Socket(_ipAddress, portNo);
br = new BufferedReader(
new InputStreamReader(socket.getInputStream(), "UTF-8"));
bos = new BufferedOutputStream(socket.getOutputStream());
send = "hi server\r\n";
buffer = send.getBytes("UTF-8");
bos.write(buffer,0,buffer.length);
bos.flush();
msg = br.readLine();
System.out.println("Msg is :"+msg);
bos.close();
br.close();
socket.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return msg;
}

注意:
先谢谢你的帮助.. !!