简体   繁体   中英

Why am I getting an error “class not found .Error while loading class”?

I have an interface and a servlet file ,whenever I try to run the application program it gives me following error

SEVERE: Class [ LDir/DirSessionLocal; ] not found. Error while loading [ class DirServlet ]

code for interface

package Dir;

import javax.ejb.Local;


@Local
public interface DirSessionLocal {

String getContact(String name1);

String getDetails(String name2);

void rater(String r);

}

code for servlet

import Dir.DirSessionLocal;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(urlPatterns = {"/DirServlet"})
public class DirServlet extends HttpServlet {
@EJB
private DirSessionLocal dirSession;

/**
 * Processes requests for both HTTP
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet DirServlet</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet DirServlet at " + request.getParameter("name") + "</h1>");
        out.println("<br>");
        out.println("<h1>" + request.getParameter("nameD") + "</h1>");
        out.println("<br>");
        out.println("<h1>" + request.getParameter("rate") + "</h1>");
        String a=request.getParameter("nameD");
        if(a.equals("abc"))

         out.println("<h1>" + dirSession.getContact(a)  + "</h1>");
        out.println("</body>");
        out.println("</html>");
    } finally {            
        out.close();
    }
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
 * Handles the HTTP
 * <code>GET</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Handles the HTTP
 * <code>POST</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Returns a short description of the servlet.
 *
 * @return a String containing servlet description
 */
@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>

}

It means that the JVM running your servlet / webapp cannot find the ".class" file for a class with the name Dir.DirSessionLocal .

Depending on how you are "deploying" your servlet, you either need to add the missing class to a JAR file, an WAR file, the webapp's tree on the web server, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM