码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-07-27 21:00:32      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:表单开发   文本框   密码框   登录   jsp   

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

标签:表单开发   文本框   密码框   登录   jsp   

原文地址:http://blog.csdn.net/tuke_tuke/article/details/47090179

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!