遨翔在知識的海洋裡----(jsp)

遨翔在知識的海洋裡發表於2018-04-13

新建專案

遨翔在知識的海洋裡----(jsp)

遨翔在知識的海洋裡----(jsp)

jsp宣告 jsp表示式 page標籤

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<% 
	String path = request.getContextPath();
	
%>
<%@ page import="java.text.*" %>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
	<h1>hello world</h1>
	<!-- 我是註釋 -->
	<%-- jsp --%>
	<%-- // 11 jsp --%>
	<%! 
		String s = "jie";
		int add(int x,int y){
			return x+y;
		}
	%>
	
	<% out.println("hellow world"); %>
	hellow,<%= s %><br>
	x+y=<%= add(10,5) %>
	<% 
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		String s = sdf.format(new Date());
	%>
	今天是: <%= s %>
</body>
</html>
複製程式碼

遨翔在知識的海洋裡----(jsp)

9*9演算法

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%!
	String printMultiTable()
	{
		String s = "";
		for(int i=1;i<=9;i++)
		{
			for(int j=1;j<=i;j++)
			{
				s+=i+"*"+j+"="+(i*j)+"&nbsp;&nbsp;&nbsp;&nbsp;";
			}
			s+="<br>";
		}
		return s;
	}

	void printMultiTable2(JspWriter out) throws Exception
	{
		for(int i=1;i<=9;i++)
		{
			for(int j=1;j<=i;j++)
			{
				out.println(i+ "*" +j+ "=" + (i*j) + "&nbsp;&nbsp;&nbsp;");
			}
			out.println("<br>");
		}
	}
%>
<%= printMultiTable()  %>
<br>
<% printMultiTable2(out);  %>
</body>
</html>
複製程式碼

遨翔在知識的海洋裡----(jsp)

修改tomcat埠

遨翔在知識的海洋裡----(jsp)

相關文章