欢迎来到代码驿站!

JSP代码

当前位置:首页 > 软件编程 > JSP代码

jsp中变量及方法的声明与使用

时间:2021-02-19 15:20:48|栏目:JSP代码|点击:

本文实例讲述了jsp中变量及方法的声明与使用。分享给大家供大家参考,具体如下:

<%@ page language="java" import="java.util.*" contentType="text/html;charset=GBK"%>
<%
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>JSP 中声明的使用</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>
  <h1 align="center">演示声明的使用</h1>
  <%--声明变量--%>
  <%!long i = 1,j=1; %>
  <%!String name="陈宁"; %>
  <%!String name2="官林辉"; %>
  <%--声明方法--%>
  <%!public String sayHello(String who)
   {
   return "您好:"+who;
   }
   %>
   <p align="center">
   <%
   out.println(sayHello(name));
   out.println("<br>");
   out.println("您是第"+i+"个访问本网站的用户!");
   i++;
   %>
   <% Date time = new Date();
    out.write(time.toLocaleString());
   %>
   </p>
   <p align="center">
   <%=sayHello(name2)%> 
   <br>
   您是第<%= j%>个访问本网站的用户!
   <%j++;%>
   </p>
 </body>
</html>

希望本文所述对大家jsp程序设计有所帮助。

上一篇:jsp实现点击help打开chm文件

栏    目:JSP代码

下一篇:jsp ${param.id}用法

本文标题:jsp中变量及方法的声明与使用

本文地址:http://www.codeinn.net/misctech/66089.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有