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
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

3,890 views 15 38
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you