2 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊
方法如下:
USERFORM.JSP
<%@ page language="java"
contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>用戶表單</title>
</head>
<body>
<form
action="DoGetDemo" method="get">
用戶名:<input type="text"
name="username"/><br>
密碼:<input type="password"
name="password"/><br>
<input type="submit"
value="提交"/>
<input type="reset"
value="重置"/>
</form>
</body>
</html>
OK,接下來(lái)相對(duì)應(yīng)的Servlet代碼如下:
package com.javaweb.ch10;
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 DoGetDemo extends HttpServlet {
public
void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb2312");
String username = request.getParameter("username");
String password = request.getParameter("password");
out.println("<html>");
out.println("<body>");
out.println("用戶名:" + username +
"<br>");
out.println("密碼:" + password);
out.println("</body>");
out.println("</html>");
}
}

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
快捷鍵不知道有沒(méi)有,不過(guò)我一般這樣弄也挺快的,一般我們寫(xiě)servlet時(shí)讓那個(gè)類繼承自HttpServlet,ctrl+s保存一下,然后選中你的類名,右擊鼠標(biāo),然后點(diǎn)Override/Implment Methods,選擇doGet點(diǎn)OK就有了。
- 2 回答
- 0 關(guān)注
- 1768 瀏覽
添加回答
舉報(bào)