我第一次尝试在我的 servlet 中编写注释。@WebServlet
工作正常。当我添加时@webInitParam
,我得到了红线。此外,当我尝试使用@POST
它给我的注释时"POST cannot be resolved to a type"
。这是我的代码:
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Servlet implementation class Calc
*/
@WebServlet (loadOnStartup = 1 , urlPatterns = { "/CoolPage" } ,
initParams = {
@WebInitParam(name="text" , value="hello" , description="simple text"),
@WebInitParam(name="times", value="10" , description="times to print")
}
)
public class Calc extends HttpServlet {
private static final long serialVersionUID = 1L;
public Calc() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@POST
protected void doThePost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Inside the POST method");
String username = request.getParameter("userName");
String password = request.getParameter("password");
request.setAttribute("userName", username);
request.setAttribute("password", password);
RequestDispatcher rd = request.getRequestDispatcher("jspGetting.jsp");
rd.forward(request, response);
}
}