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列)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值