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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值