my eclipse中servlet的doget方法快捷键
2个回答
展开全部
快捷键不知道有没有,不过我一般这样弄也挺快的,一般我们写servlet时让那个类继承自HttpServlet,ctrl+s保存一下,然后选中你的类名,右击鼠标,然后点Override/Implment Methods,选择doGet点OK就有了。
追问
是不是,dopost方法也是这样的啊!反正就是两个方法都是代码都是同时生成的啊?感谢啊,,,,
追答
一般父类的doGet和doPost都会重写的,看你有没有需要了。还有init和destroy,不是同时生成,是你重写不重写。。
推荐于2017-10-13 · 知道合伙人互联网行家
关注
展开全部
方法如下:
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,接下来相对应的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>");
}
}
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,接下来相对应的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>");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询