我正在通过视频教程学习J2EE并坚持使用第一个基本的servlet。在视频上页面加载成功,但不在我的浏览器上。作为讲师,我做了一切。服务器运行良好。检查了8080和4848.我也向glassfish添加了servelet,但仍然是错误404.谢谢。
package com.airline.controllers;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class AddPassenger
*/
@WebServlet("/AddPassenger")
public class AddPassenger extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddPassenger() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.println("<html><body>");
out.println("<h2>Welcome to My Airlines!!</h2>");
out.println("</body></html>");
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
答案 0 :(得分:-1)
选择 Glass Fish服务器,右键单击并选择&#39; 发布&#39;。现在刷新页面,这应该可行。