建站学 - 轻松建站从此开始!

建站学-个人建站指南,网页制作,网站设计,网站制作教程

当前位置: 建站学 > 网站开发 > JSP教程 >

JSP基础(3)

时间:2009-12-10 23:02来源: 作者: 点击:
四、实例 登陆页面:index.jsp Html代码 %@ page language=java pageEncoding=UTF-8 contentType=text/html; charset=UTF-8 % html head title系统登录/title meta http-equiv=Content-Type content=text/html; cha


四、实例
登陆页面:index.jsp

Html代码
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>   
<html>   
<head>   
  <title>系统登录</title>   
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">   
  <link href="css/vbulletin.css" rel="stylesheet" type="text/css">   
  <style type="text/css">   
   .btn {   
    font-family: "Tahoma", "宋体";   
    font-size: 9pt;   
    color: #001E3C;   
    BORDER-BOTTOM: #6794BC 1px solid;   
    BORDER-LEFT: #8BB8E0 1px solid;   
    BORDER-RIGHT: #6794BC 1px solid;   
    BORDER-TOP: #8BB8E0 1px solid;   
    background-image: url(image/buttonbg.gif);   
    CURSOR: hand;   
    font-style: normal;   
    padding-left: 3px;   
    padding-right: 3px;   
   }   
  </style>     
  <script type="text/javascript">   
   function doLogin(){   
    var vform = document.loginform;   
    if(!loginform.username.value){   
     alert("请输入用户名!")   
     return;   
    }   
        
    if(!loginform.password.value){   
     alert("请输入密码!")   
     return;   
    }   
      
    vform.submit();   
       
   }   
  </script>   
</head>   
<body topmargin="0" leftmargin="0" >   
  <form action="receive.jsp" name="longinForm" method="post">   
   <table width="100%" height="100%">    
    <tr>   
     <td align="center" valign="middle">   
      <TABLE id="form1"       
       cellspacing="0" cellpadding="0" border="0" style="width: 500;">   
       <CAPTION style="display: none">   
       </CAPTION>   
       <TR>   
        <TD>   
         <TABLE width="100%" height="100%" cellspacing="0"    
          cellpadding="0" border="0" style="table-layout: fixed">   
          <TR>   
           <TD valign="top">   
            <FIELDSET id="form1_group0" style="width: 100%;">   
             <LEGEND>系统登录</LEGEND>   
             <DIV>   
              <DIV  style="width: 100%; height: 100%">   
               <TABLE  width="100%" cellspacing="0"   
                cellpadding="4" border="0" style="table-layout: fixed;">   
                <COLGROUP>   
                 <COL width="100"></COL>   
                 <COL width="50%"></COL>   
                 <COL width="100"></COL>   
                 <COL width="50%"></COL>   
                </COLGROUP>   
                <TR>   
                 <TD  align="right">   
                  用户名   
                 </TD>   
                 <TD class="InnerTableContentCell">   
                  <input type="text" name="username"   
                   style="width: 100%;">   
                 </TD>   
                 <TD  align="right">   
                  密码   
                 </TD>   
                 <TD>   
                  <input type="password" name="password"   
                   style="width: 100%;" />   
                  <input type="hidden" name="action2" value="0">   
                 </TD>   
                </TR>   
                <TR>   
                 <TD colSpan="4"   
                  align="right">   
                  <input type="button" name="login" value="登录" onclick="this.form.submit();"   class="btn"/>   
                 </TD>   
                </TR>   
               </TABLE>   
              </DIV>   
             </DIV>   
            </FIELDSET>   
           </TD>   
          </TR>   
         </TABLE>   
        </TD>   
       </TR>   
      </TABLE>   
     </td>   
    </tr>   
   </table>   
  </form>   
</body>   
</html>   
接收数据页面:receive.jsp

Html代码
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" info="动作标签"%>   
   
<jsp:useBean id="userVo" class="exercise.vo.UserVo" scope="request">   
  <jsp:setProperty name="userVo" property="name" param="username"/>   
  <jsp:setProperty name="userVo" property="password" param="password"/>   
</jsp:useBean>   
   
<html>   
  <head>   
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >   
    <link href="css/vbulletin.css" rel="stylesheet" type="text/css">   
  </head>   
     
  <body>    
    This is my JSP page. <br>   
    <hr>用&lt;jsp:getProperty&gt;获取表单中提交过来的值<br>   
    name:<jsp:getProperty property="name" name="userVo"/><br>   
    password:<jsp:getProperty property="password" name="userVo"/>   
    <br><br><hr>   
    <%   
      out.println("从vo对象中直接获取:<br> name:"+userVo.getName()+   
      "<br>password:"+userVo.getPassword()+"<br>");   
      String serviceName = request.getServerName();//1.jsp内部的request对象   
      out.println("<br><hr>服务器名: "+serviceName);   
      out.println("<br>MIME类型: "+response.getContentType());//2.jsp内部的response对象   
      session.setAttribute("sessionName","jsp内部的session对象");//3.jsp内部的session对象   
      out.println("<br>session对象: "+session.getAttribute("sessionName"));//4.jsp内部的out对象   
      pageContext.setAttribute("pageContext","上下文环境的引用");//5.jsp内部的pageContext对象   
     //6. application   
     //7. config   ServletConfig的实例   
     //8. page   java.lang.Object的实例   
     //9. exception  必须在page指令中isErrorPage=true的页面使用   java.lang.Throwable的一个实例   
     String info = pageContext.getServletContext().getServerInfo();   
     out.println("获取page指令中的info属性:"+info);   
    %>   
  </body></html> (责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片