这是jsp页面代码 <body> <h1>第一个myeclipse servlet程序</h1> <!--用get方式(表单没有指定method,或者正常的URL,请求都是get方式),请求一个servlet --> <a href="servlet/HelloServlet">get方式请求HelloServlet </a> <%--post请求,写一个表单,指定method=post --%> <form action="servlet/HelloServlet" method="post"> <input type="submit" value="post请求servlet" /> </form> </body> 以下是servlet代码 package servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servlet; import javax.servlet.ServletConfig; 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 HelloServlet */ @WebServlet("/servlet/HelloServlet") public class HelloServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public HelloServlet() { super(); // TODO Auto-generated constructor stub } /** * @see Servlet#init(ServletConfig) */ public void init(ServletConfig config) throws ServletException { // TODO Auto-generated method stub } /** * @see Servlet#destroy() */ public void destroy() { // TODO Auto-generated method stub } /** * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse * response) */ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("doGet处理get请求 ");// 这是后台显示的 PrintWriter pw = response.getWriter(); response.setContentType("text/html;charset=utf-8"); pw.println("<strong>helloServelt</strong>"); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("dopost处理post请求 ");// 这是后台显示的 PrintWriter pw = response.getWriter(); response.setContentType("text/html;charset=utf-8"); pw.println("<strong>helloServelt</strong>"); } }
网上看到说是servlet 3.0的新特性,不使用xml注解,也是可以的,但是我的却是空白页面?这是为何?
时间啊
慕的地8582982