|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
package com.v512.webproject2;
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 LoginFormServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print("<form method=\"post\" action=\" " request.getContextPath() "/servlet/loginForm\" >");
out.println("用户名:<input type='text' name='username' size='18'>" "<br>");
out.println("密 码:<input type='password' name='password' size='20'>" "<br>");
out.println("<input type='submit' name='submit' value='提交'>");
out.print("<input type='reset' name='reset' value='重置'>");
out.print("</form>");
out.println("request.getContextPath" "用来活动web应用的名字webprject2" "<br>");
out.println("用post的提交方式提交到自己的post" "<br>");
out.println("解决乱码request.setCharacterEncoding(\"utf-8\")" "<br>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
request.setCharacterEncoding("utf-8");
out.print("用户名:" request.getParameter("username") "<br>");
out.print("密 码:" request.getParameter("password") "<br>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
|
|