JSP之表单提交get和post的区别详解及实例

前端之家收集整理的这篇文章主要介绍了JSP之表单提交get和post的区别详解及实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

JSP之表单提交get和post的详解及实例

一 get和post的区别

二 实战(post方式提交)

1、login.jsp

  1. <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" >
  10. <title>My JSP 'login.jsp' starting page</title>
  11. <Meta http-equiv="pragma" content="no-cache">
  12. <Meta http-equiv="cache-control" content="no-cache">
  13. <Meta http-equiv="expires" content="0">
  14. <Meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  15. <Meta http-equiv="description" content="This is my page">
  16. <!--
  17. <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" >
  18. -->
  19. </head>
  20. <body>
  21. <h1>用户登录</h1>
  22. <hr>
  23. <form action="dologin.jsp" name="loginForm" method="post">
  24. <table>
  25. <tr>
  26. <td>用户名</td>
  27. <td><input type="text" name="username"/></td>
  28. </tr>
  29. <tr>
  30. <td>密码:</td>
  31. <td><input type="password" name="password"/></td>
  32. </tr>
  33. <tr>
  34. <td colspan="2"><input type="submit" value="登录"></td>
  35. </tr>
  36. </table>
  37. </form>
  38. </body>
  39. </html>

2、dologin.jsp

  1. <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" >
  10. <title>My JSP 'dologin.jsp' starting page</title>
  11. <Meta http-equiv="pragma" content="no-cache">
  12. <Meta http-equiv="cache-control" content="no-cache">
  13. <Meta http-equiv="expires" content="0">
  14. <Meta http-equiv="keywords" content="keyword1,keyword3">
  15. <Meta http-equiv="description" content="This is my page">
  16. <!--
  17. <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" >
  18. -->
  19. </head>
  20. <body>
  21. <h1>登录成功</h1>
  22. <hr>
  23. </body>
  24. </html>

 三 运行结果

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

猜你在找的Jsp相关文章