Java Tutorial/JSP/String — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 05:07, 1 июня 2010

Creating a String

<HTML>
  <HEAD>
    <TITLE>Creating a String</TITLE>
  </HEAD>
  <BODY>
    <H1>Creating a String</H1>
    <%
        String greeting = "Hello from JSP!";
        out.println(greeting);
     %>
  </BODY>
</HTML>





Getting String Length

<HTML>
  <HEAD>
    <TITLE>Getting String Length</TITLE>
  </HEAD>
  <BODY>
    <H1>Getting String Length</H1>
    <%
        String s1 = "Hello from JSP!";
        out.println("\"" + s1 + "\"" + " is " + s1.length()
            + " characters long.");
     %>
  </BODY>
</HTML>





Use for loop to display string array

<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%@ page session="false" %>
<%
   String[] colors = {"red", "green", "blue"};
   for (int i = 0; i < colors.length; i++) {
      out.print("<P>" + colors[i] + "</p>");
   }
%>