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

3 votes
Joseph 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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,799 views 26 10
Join discussion

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