'JSP'에 해당되는 글 7건
- 2008/10/27 How to set and get sessions on JSP code ?
- 2008/10/27 How to add a declaration on JSP code ?
- 2008/10/27 How to include file in JSP ?
- 2008/10/27 How to print out text strings on HTML directly ?
- 2008/10/27 Put Date Time on HTML
- 2007/08/31 Send An Email Using A Bean
- 2007/08/31 JQuery And Function Chaining
save_my_name,jsp
<%
String name = request.getParameter( "username" );
session.setAttribute( "theName", name );
%>
<HTML>
<BODY>
<A HREF="next_page.jsp">Continue</A>
</BODY>
</HTML>
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
// printf( "a.out");
/*
printf( "b.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>
<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 %>.
Here's the simple example.
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>
<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,
In JSP, you can simply put Date Time as below.
Prev



Rss Feed