NewOnTheBlockTim
NewOnTheBlockTim

Reputation: 1

hello world jsp error

I am trying to reproduce the example from the JSP tutorial:

http://www.jsptut.com/Scriptlets.jsp

I have entered the code

<HTML>
<BODY>

    <%
    // This is a scriptlet.  Notice that the "date"
    // variable we declare here is available in the
    // embedded expression later on.
    System.out.println( "Evaluating date now" );
    java.util.Date date = new java.util.Date();
    %>
Hello!  The time is now `<%= date %>`
</BODY>
</HTML>

and saved it both as hello.jsp and index.jsp.

However all I get is Hello World, but not the date from the JAVA part.

The WEB server logs do not indicate any errors. What am I doing wrong?

Thanks Tim

Upvotes: 0

Views: 131

Answers (2)

Biu
Biu

Reputation: 1076

Add this line <%= new java.util.Date() %> to print to your web page, use jsp expression which is <%= %> to print stuff to the browser. Jsp expression will convert anything to string for you. Note no semicolon

Upvotes: 0

Ahmed Elmir
Ahmed Elmir

Reputation: 163

It is important to recognize that whatever is in between

<%=  %> 

can only be a printable token, such as string, int long etc...

and whatever is between

<% %>

is ordinary java code.

THerefore, simply change your code to:

 <%= date.toString() %>

and it should work, since it is a string that you are printing.

Upvotes: 2

Related Questions