jsp 基础

1.<%= %> expression

example:

<body>
Hello!  The time is now <%= new java.util.Date() %>
</body>

2.<% %> scriptlet

example:

<%
    System.out.println( "hello world" );
%>

3.<%@ %> derective

example:

<%@ page import="java.util.*" %>

4.<%! %> declaration

example:

<body>
<%!
    java.util.Date getDate()
    {
        return new java.util.Date();
    }
%>
Hello!  The time is now <%= getDate() %>
</body>

5.<type:tags> jsp tags

example:

<jsp:include page="hello.jsp"/>

6.sessions

an object associated with a visitor

like a Hashtable

example:

<%
   session.setAttribute( "theName", "name" );
%>
<body>
Hello, <%= session.getAttribute( "theName" ) %>
</body>

7.beans

compile

make sure it is available in the web-server's classpath

example:

package user;
public class UserData {
    String username;
    public void setUsername( String value )
    {
        username = value;
    }
    public String getUsername() { return username; }
}
<jsp:useBean id="user" class="user.UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<jsp:useBean id="user" class="user.UserData" scope="session"/> 
<body>
Name: <%= user.getUsername() %><br/>
</body>
posted @ 2013-04-14 12:15  国超  阅读(228)  评论(0编辑  收藏  举报