'JSP'에 해당되는 글 7건

  1. 2008/10/27 How to set and get sessions on JSP code ?
  2. 2008/10/27 How to add a declaration on JSP code ?
  3. 2008/10/27 How to include file in JSP ?
  4. 2008/10/27 How to print out text strings on HTML directly ?
  5. 2008/10/27 Put Date Time on HTML
  6. 2007/08/31 Send An Email Using A Bean
  7. 2007/08/31 JQuery And Function Chaining
2008/10/27 14:13

How to set and get sessions on JSP code ?

Here's the simple example to set and putsessions.

save_my_name,jsp
<%
   String name = request.getParameter( "username" );
  session.setAttribute( "theName", name );
%>
<HTML>
<BODY>
<A HREF="next_page.jsp">Continue</A>
</BODY>
</HTML>


save_my_name.jsp saves the user's name in the session, and puts a link to another page, next_page.jsp.
next_page.jsp shows how to retrieve the saved name.

next_page.jsp
<HTML>
<BODY>
Hello, <%=session.getAttribute( "theName" ) %>
</BODY>
</HTML>
Trackback 0 Comment 0
2008/10/27 14:07

How to add a declaration on JSP code ?

If you have developed C or C++ program, you may know below examples.

// printf( "a.out");

/*
  printf( "b.out");
*/


Above code have no bug, but no code will be compiled, because it's alldeclarations.

In JSP, you can make declarations as well. In some documents, a declarations is also called asremark.

To add a declaration, you must use the <%! and %> sequences to enclose your declarations, as shown below.
<%@ page import="java.util.*" %>
<HTML>
<BODY>
<%!
    Date theDate = new Date();
    Date getDate()
    {
        System.out.println( "In getDate() method" );
        return theDate;
    }
%>
Hello!  The time is now <%= getDate() %>
</BODY>
</HTML>

Above code is actuallydead code, because it;s surrounded with <%! and %>.
Trackback 0 Comment 0
2008/10/27 14:01

How to include file in JSP ?

Just like ASP, or PHP, JSP is also allow toinclude for programmer by include function.
Here's the simple example.
<HTML>
<BODY>
Going to include hello.jsp...<BR>
<%@include file="hello.jsp" %>
</BODY>
</HTML>
Trackback 0 Comment 0
2008/10/27 13:48

How to print out text strings on HTML directly ?

InJSP, you can print out text strings by out.println().


Here's the example.

<HTML> <BODY> <%
// This scriptlet declares and initializes "date"
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date(); %> Hello!  The time is now <%
// This scriptlet generates HTML output
out.println( String.valueOf( date )); %> </BODY> </HTML>
 
But above example can be expressed as below.
<HTML>
<BODY>
<%
    // This scriptlet declares and initializes "date"
    System.out.println( "Evaluating date now" );
    java.util.Date date = new java.util.Date();
%>
Hello!  The time is now <%= date%>
</BODY>
</HTML>

 

Both ways shows the same result, but the second is much faster and have good readability than the first. code,

Trackback 0 Comment 0
2008/10/27 13:42

Put Date Time on HTML

In JSP, you can simply put Date Time as below.


<HTML>
<BODY>
Hello!  The time is now <%= newjava.util.Date() %>
</BODY>
</HTML>
Trackback 2 Comment 0