特点:
- 内容的生成和显示分离
- 平台无关性
主流web技术:CGI、ASP、PHP、JSP
tomcat配置:
.jsp文件中的代码:<%除界面外的Java代码%>
注:out.println();输出到网页页面,System.out.println();输出到tomcat终端界面
jsp运行过程:运行着tomcat,由浏览器指定文件运行(由浏览器向tomcat申请文件,tomcat运行文件的结果生成html的内容,返回给浏览器)
注:需要把要运行的.jsp文件放到tomcat文件(或所在文件夹)的webapp文件下,浏览器通过localhost:8080/**/.jsp。
aaa.jsp:
<%
for(int i=0;i<200;i++)
{
out.println(i+" ");
}
%>
--------------------------------------------------------------
bbb.jsp:
<html>
<head>
<title>Table Ex</title>
</head>
<body>
<table border="1">
<%
for(int i=0;i<8;i++)
{
%>
<tr>
<%
for(int j=0;j<10;j++)
{
out.println("<td>"+i+":"+j+"</td>");
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>
---------------------------------------------------------------
ccc.jsp
<html>
<head>
<title>Table Ex</title>
</head>
<body>
<form action="ccc.jsp">
Name<input type="text" name="uid"><br/>
<input type="submit" value="OK">
</form>
<%
String uid=request.getParameter("uid");
if(uid!=null&&uid.length()!=0)
{
%>
<font color="red" size="20">
Hello,
<%
out.print(uid);
%>
!
</font>
<%
}
else
{
%>
<font color="red" size="20">
Please input your name!
</font>
<%
}
%>
</body>
</html>
------------------------------------------
inaaa.jsp:
<html>
<head>
<title>Table Ex</title>
</head>
<body>
<table border="1">
<%
for(int i=0;i<8;i++)
{
%>
<tr>
<%
for(int j=0;j<10;j++)
{
out.println("<td>"+i+":"+j+"</td>");
}
%>
</tr>
<%
}
%>
</table>
<hr/>
<%@ include file="aaa.jsp" %>
</body>
</html>
------------------------------------------------
JSP指令
![](https://i-blog.csdnimg.cn/blog_migrate/db6c9bbd8e8c9c1dc4219c1d40da24e4.png)
JSP脚本标签
inccc.jsp
<html>
<head>
<title>Table Ex</title>
</head>
<body>
<table border="1">
<%
for(int i=0;i<8;i++)
{
%>
<tr>
<%
for(int j=0;j<10;j++)
{
out.println("<td>"+i+":"+j+"</td>");
}
%>
</tr>
<%
}
%>
</table>
<hr/>
<jsp:include page="ccc.jsp">
<jsp:param name="uid" value="wyf"/>
</jsp:include>
</body>
</html>
gotoccc.jsp:
aaaaaaaaa
<jsp:forward page="ccc.jsp">
<jsp:param name="uid" value="wyf"/>
</jsp:forward>