doGet()方法来处理浏览器直接访问和get方式提交的表单
2016-03-18 17:03
423 查看
新建UserForm.jsp:
新建doGetDemo类:
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <%-- 表单,提交方式为get,提交到doGet--%>> <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>
新建doGetDemo类:
package web_project; 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{ //doGet方法 public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ // response.setContentType("text/html;charset=gb2312"); PrintWriter outp=response.getWriter(); // request.setCharacterEncoding("gb2312"); // String username= request.getParameter("username"); // String password=request.getParameter("password"); outp.println("<html>"); outp.println("<body>"); outp.println("用户名:"+username+"<br>"); outp.println("密码"+password); outp.println("</body>"); outp.println("</html>"); } }
相关文章推荐
- Eclipse配置NDK环境(不需要Cygwin)
- Java集合框架:总结
- 移动端H5做一个不限个数的通栏按钮 by FungLeo
- 去掉String字符串的最后一个字符
- ie11下alt+d不能用js监听问题
- Eclipse Logcat 显示配置
- mongodb 使用场景和不使用场景
- GUI登录界面
- SQL Server中的锁
- [置顶] Android中使用背景设置透明度问题总结
- leetcode--Maximum Depth of Binary Tree
- Nginx+Redis+Tomcat实现session共享的集群
- 虚拟网卡驱动
- membercache使用笔记
- 数学题-矩阵翻硬币-找规律
- 38.windbg-调试技巧(创建进程即断下、r修改控制条件跳转)
- centos 7.x 开机自启动tomcat
- 设计模式系列之(1):单例模式
- 安全模式不能删除使用SET SQL_SAFE_UPDATES = 0;
- Gradle for Android 第七篇( Groovy入门 )