servlet开发9-JSP sample1

前言:

JSP 包含了HTML,Java Script, CSS/DIV等, 学习JSP之前起码保证对HTML有个了解。


JSP本质还是Servlet, 不过用Servlet写一堆的out.println来输出界面太麻烦了, 所以出现了JSP,专注于界面方面, Servlet只需要关注数据/业务处理就好。



sample1:

在MyApp项目目录下创建一个index.jsp, 只写下面三行代码:

<%
	response.sendRedirect("reguser.jsp");
%>

在浏览器输入地址访问:

http://localhost:8080/MyApp/index.jsp


接着创建reguser.jsp:

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>输入用户名</title>
</head>

<body>

<br>
<form name="form" action="weluser.jsp" method="get">
<table width="200" border="1" align="center">
<tr>
<td> 用户名:</td>
<td> <input type="text" name="username" size="10"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="提交"> | <input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>

接着创建weluser.jsp:

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>欢迎您</title>
</head>

<body>
<center>
<%
String username = request.getParameter("username");
out.println("Welcome "+username+"!");
//获取用户名信息
//输出欢迎该用户的提示信息
%>
</center>
</body>

</html>


重新浏览器输入地址访问:

http://localhost:8080/MyApp/index.jsp

即可看到效果


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值