当前位置: 动力学知识库 > 问答 > 编程问答 >

jsp - java.lang.ClassCastException: Servlet.Telnet cannot be cast to javax.servlet.Servlet

问题描述:

I want to implement a servlet and call it in a WebApp.

I am constantly get java.lang.ClassCastException: Servlet.Telnet cannot be cast to javax.servlet.Servlet from the Apache Tomcat Server. I made sure my class extends HttpServlet this is my code:

package Servlet;

import java.io.IOException;

import java.io.PrintStream;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.net.telnet.TelnetClient;

public class Servlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

try {

TelnetClient telnet = new TelnetClient();

telnet.connect(request.getParameter("router"), 23);

PrintStream output = new PrintStream(telnet.getOutputStream());

output.println(request.getParameter("login"));

output.flush();

output.println(request.getParameter("password"));

output.flush();

out.printf("SUCCESS");

telnet.disconnect();

} catch (Exception e) {

e.printStackTrace();

out.printf("ERROR");

}

}

网友答案:

I renamed the package and the class and it works perfectly.

分享给朋友:
您可能感兴趣的文章:
随机阅读: