0
私はこの質問がたくさん頼まれていることを知っていますが、私はすべてを試しましたが、誰かが助けてくれることを望んで、まだ私のために働いていません。Javaサーブレットon eclipse:サーブレット・クラスのインスタンス化エラー| ClassNotFoundException
私はこのエラーを示し続け、日食とサーバー上のサーブレットページを実行しようとしている:
ここに私のソースコードがあります:
私は単純なサーブレットのページを書いてきましたそれは、サーバー上で実行されている参照してください:
package main.java.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StationsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public StationsServlet() {
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println("<html>");
writer.println("<body>");
writer.println("Hello");
writer.println("</body></html>");
writer.flush();
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
}
私のweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>weather-files-war</display-name>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>stationsServlet</servlet-name>
<servlet-class>main.java.servlet.StationsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>stationsServlet</servlet-name>
<url-pattern>/stations</url-pattern>
</servlet-mapping>
</web-app>
そして最後に、私のフォルダ/モジュール構造:
- PS:サーブレットクラスを打つとき、私はhomepage.jspを作成し、それがサーバー上で正常に動作しています、問題があります。
サーブレットのクラスをWARモジュールに移動すると、サーブレットの注釈が試されましたが、依存関係などの問題があると思います。 –
注釈をコピーしてアノテーションを付けました。 – pavlo
StationsServletファイルを削除して、再度作成してください。 – pavlo