//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>My JSP 'index.jsp' starting page</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>
杨辉三角 <br>
<%
int[][] a; int flag = 20; a = new int[20][20]; a[0][0] = a[1][0] = a[1][1] = 1; for ( int i = 2; i
< 20; i++ )
{
for ( int j = 0; j < 20; j++ )
{
if ( j >= 1 )
{
a[i][0] = 1; a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
}
for ( int i = 0; i < 20; i++ )
{
for ( int p = flag; p > 0; p-- )
{
out.print( " " );
}
for ( int j = 0; j < 20; j++ )
{
if ( a[i][j] > 0 )
{
out.print( " " + a[i][j] );
}
}
out.print( "<br> " ); flag--;
}
%>
</body>
</html>
jsp打印杨辉三角(myeclipse 10 +jdk1.8.0 +tomcat )
需要 <% java代码 %>
然后是怎么样才能把输出打印到网页上,也是百度了一下
可以直接通过 out.printlin(" ") 只不过 想要打印空格得需要  
要是想要换行需要使用H5强制换行符 <br>
都弄好了后,就打开tomcat服务:
图上是我的已经打开了。
然后就可以把你的项目加载到服务里:
然后可以直接通过myeclipse 客户端查看网页效果,也可以通过浏览器进行访问啦
一般网址格式:http://localhost:8080/test/index.jsp
显示你的ip:tomcat默认网端/你的项目名/二级子目录....../最后是你的访问目标网页
jsp打印杨辉三角