Hi Im a complete novice when it coems to using JSP. Im trying to use a method found in a java class from the same project to output the date. The java class looks like this:
package my_java_classes;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class myFormattedDate
{
final String DATE_FORMAT = "MM/dd/yyyy";
final SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.UK);
public String getFormattedDate()
{
String formattedDate = formatter.format( new Date() );
return formattedDate;
}
}
I’ve tried looking around and it seems that you can call java classes in JSP like this:
<%@ page import = "my_java_classes.myFormattedDate.java" %>
But this tells me that “it cannot be resolved.” Whats the problem here?
Also correct me if I’m wrong but you can also call other JSP classes using the:
<%@ include file='jsp_page_name.jsp'%>
Cheers
To import a class, just use the class identifier.
no extra .java is needed.