慕粉2139036677
2017-03-04 10:55
<body> <h1>第一个servlet小例子</h1> <a href="servlet/HelloServlet">get方式请求HelloServlet</a><br> <form action="servlet/HelloServlet" method="post"> <input type="submit" value="用post方式提交HelloServlet" /> </form> </body>
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("处理doGet请求"); PrintWriter out=response.getWriter(); out.println("HelloServlet"); } /* (non-Javadoc) * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("处理doPost请求"); PrintWriter out=response.getWriter(); out.println("HelloServlet from post"); }
<servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>servlet.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/servlet/HelloServlet</url-pattern> </servlet-mapping>
兄弟,显示什么错误?我这边跑你的代码可以诶
JAVA遇见HTML——Servlet篇
160613 学习 · 1029 问题
相似问题