SoFunction
Updated on 2025-04-05

Declaration and use of variables and methods in jsp

This article describes the declaration and use of variables and methods in jsp. Share it for your reference, as follows:

<%@ page language="java" import=".*" contentType="text/html;charset=GBK"%>
<%
String path = ();
String basePath = ()+"://"+()+":"+()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>">
  <title>JSP Use of declarations</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="">
 -->
 </head>
 <body>
  <h1 align="center">Use of demonstration statements</h1>
  <%--Declare variables--%>
  <%!long i = 1,j=1; %>
  <%!String name="Chen Ning"; %>
  <%!String name2="Official Lin Hui"; %>
  <%--Declaration method--%>
  <%!public String sayHello(String who)
   {
   return "Hello:"+who;
   }
   %>
   <p align="center">
   <%
   (sayHello(name));
   ("<br>");
   ("You are the first"+i+"A user who visits this website!");
   i++;
   %>
   <% Date time = new Date();
    (());
   %>
   </p>
   <p align="center">
   <%=sayHello(name2)%> 
   <br>
   You are the first<%= j%>Users who visit this website!
   <%j++;%>
   </p>
 </body>
</html>

I hope this article will be helpful to everyone's jsp programming.