It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Confluence plugin - servlet cannot be cast

Hi all,

I have registred servlet in atlassian-plugin.xml:

<servlet name="xls export servlet" key="xlsExport" class="com.mycomp.confluence.plugin.servlet.XlsExport">
<description></description>
<url-pattern>/xlsExport</url-pattern>
</servlet>

Tha class of servlet is following (I only test it):

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class XlsExport2 extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet XlsExport2</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet XlsExport2 at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
public String getServletInfo() {
return "Short description";
}
}

When I call this servlet in velocity template like this:

 /confluence/plugins/servlet/xlsExport

, it still throw this exception:

getServlet Unable to create servlet
java.lang.ClassCastException: com.mycomp.confluence.plugin.servlet.XlsExport cannot be cast to javax.servlet.http.HttpServlet 

What is wrong? I dont have any idea... Thanks for reply

2 answers

1 accepted

4 votes
Answer accepted
Joe Clark Atlassian Team Aug 04, 2011

In your pom.xml, make sure that your dependency on the java servlet API is set to "Provided":

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>

Hi,

Your class is called "XlsExport2" but your definition is using "XlsExport"!

-Bjarni

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published yesterday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

70 views 0 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you