import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset = GBK";
public LoginServlet() {
super();
}
public void init() throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setCharacterEncoding("GB2312");
PrintWriter out = response.getWriter();
try {
String username = request.getParameter("username");
String password = request.getParameter("parssword");
if (username.equals("") || password.equals("")) {
userInterface(response);
} else {
out.println("<b>" + username + "</b> 欢迎第一次使用Servlet<br/>");
out.println("<b> 今天的日期是 : </b>" + new Date());
}
} catch (Exception e) {
userInterface(response);
}
}
public void userInterface(HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>loginservlet</TITLE></HEAD>");
out.println(" <BODY bocolor=\"#ffffff\">");
out.print(" <h1 align=center> 欢迎第一次使用servlet</h1>");
out.print("<form method = post action=/ServletModule/loginservlet");
out.println("<br>");
out.println("用户名: <input type='text' name='username'><br/>");
out.println("密码: <input type='passowrd' name='password'><br/>");
out.println("input type=submit value='提交'><br/>");
out.println("</form>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public void destroy() {
}
}
//在 web project 下
请问下面这段代码在 Eclipse+MyEclipse+tomcat 下 如何编译呢?
[此贴子已经被作者于2006-9-24 21:48:06编辑过]