欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

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

发布时间:2025/3/20 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 表单开发(一):获取文本框和密码框数据 用户登录网页 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
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都是在服务器端运行的后端脚本语言

总结

以上是生活随笔为你收集整理的表单开发(一):获取文本框和密码框数据 用户登录网页的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。