表单开发(一):获取文本框和密码框数据 用户登录网页
生活随笔
收集整理的這篇文章主要介紹了
表单开发(一):获取文本框和密码框数据 用户登录网页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
passwordForm.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();//獲取上下文路徑
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!--以上主要是獲取路徑地址 http://localhost:8080/projectname/jspname-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><!-頭部類容--> <title>My JSP 'passwordForm.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head> <body><!--javascript語言寫的代碼塊--><script type="text/javascript">function login(){if(document.loginform.zhanghao.value==""){window.alert("賬號不能為空!");return ;}if(document.loginform.mima.value==""){window.alert("密碼不能為空!");return ;}loginform.submit();}</script><form action="passwordForm_result.jsp" name="loginform"><h4 align="center"><b>歡迎登陸學生管理系統</b></h4><br> <table align="center"><tr><td>請輸入賬號:</td><td><input name="zhanghao" type="text"> </td></tr><tr><td>請輸入密碼:</td><td><input name="mima" type="password"> </td></tr><tr><td></td><td><input type="button" value="登錄" onclick="login()"> <input type="button" value="忘記密碼?"></td></tr></table> </form></body>
</html>
<!--passwordForm_result.jsp-->
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"> <title>My JSP 'passwordForm_result.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><% String user=request.getParameter("zhanghao");String password=request.getParameter("mima"); %><table align="center"><tr><td>賬號為:</td><td><%= user %></td></tr><tr><td>密碼為:</td><td><%= password %></td></tr></table> </body>
</html>
結果如圖所示:
查看passwordForm_result.jsp的網頁源代碼
會發現java代碼沒有顯示,是因為html和javascript都是前端語言,是瀏覽器編譯運行的,而jsp/php/asp都是在服務器端運行的后端腳本語言
總結
以上是生活随笔為你收集整理的表单开发(一):获取文本框和密码框数据 用户登录网页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表单标签form的简单使用
- 下一篇: 表单开发(二):获取单选按钮,多行文本框