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

来源:互联网 发布:手机淘宝评论在哪里看 编辑:程序博客网 时间:2024/06/05 10:43
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都是在服务器端运行的后端脚本语言

1 0
原创粉丝点击