日期:2014-05-20 浏览次数:20947 次
package test; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException ,IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title>"); out.println("This is my first Servlet"); out.println("</title></head><body>"); out.println("<h1>Hello,World!</h1>"); out.println("</body></html>"); } }
package org.xiong.servletdemo; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ServletDemo extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title>"); out.println("This is my first Servlet"); out.println("</title></head><body>"); out.println("<h1>Hello,World!</h1>"); out.println("</body></html>"); } public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException { this.doGet(request,response); } }
------解决方案--------------------
javac -cp jar路径 *.java
------解决方案--------------------
tomcat似乎需要配置java_home。 配置了吗?