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>輸入用戶名</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 background = "images/bg.gif">
<script language = "javascript">
function checkuser(){
if(document.form.username.value ==""){ //如果username輸入框內容爲空
alert("請輸入用戶名") //彈出提示對話框
document.form.username.focus(); //光標停留在username輸入框
}
Else
document.form.submit(); //否則提交表單
}
</script>
<br>
<form name = "form" action = "weluser.jsp" method = "get">
<table width = "200" border = "1" align = "center">
<tr>
<th> 用戶名:</th>
<td> <input type = "text" name = "username" size = "10">
</tr>
<tr>
<td colspan = "2" align = "center">
<input type = "button" value = "提交" onclick = "checkuser()">|<input type = "reset" value = "重置">
<!-- 定義一個單擊事件 當用戶點擊“提交” 按鈕將出發JavaScript中定義的checkuser()方法-->
</td>
</tr>
</table>
</form>

</body>
</html>



輸出歡迎信息 WelCome XiAoOMAn!


<%@ 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>歡迎您</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 background = "images/bg.gif">
<center>
<%
String username = request.getParameter("username"); //獲取用戶信息
out.println("Welcome " + username + "!"); %>
</center>
<br>
</body>
</html>




tips:


&nbsp
在頁面上顯示空格,有時候表的單元個如果沒有字就不顯示內邊匡了,加上這個,就可以顯示了。
因爲,html中只承認最多兩個連在一起的空個,所以,需要多個空格的時候,就要用 來表示。


標籤

<table>

設定一格表格
<table width = "200" border = "1" align = "center">
其中 width便是寬度設定 border設定邊框粗細 align設置表格位置(center 居中)


<tr>

tr 定義一行
td定義行中的一段
th定義行中的一段 黑體

<tr>
<td colspan = "2" align = "center">
<input type = "submit" value = "提交">|<input type = "reset" value = "重

置">
</td>
</tr>
colspan屬性設置表元橫跨的列數 (以上排爲 2列)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章