300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 表单开发(一):获取文本框和密码框数据 用户登录网页

表单开发(一):获取文本框和密码框数据 用户登录网页

时间:2020-07-23 15:47:44

相关推荐

表单开发(一):获取文本框和密码框数据  用户登录网页

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都是在服务器端运行的后端脚本语言

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。