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
Accepted answer
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
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

104 views 3 4
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