Mike said:
Anton,
Thank you for your response, sorry for mixing up terminology. I want
to build
this date limiting code into my web page sitting on my server. So is
the code you posted below what I need? if yes, I'm confused on how to
limit by monday mornings and fri afternoons.
Thanks for any assistance.
Mike
Again, it depends on what you're using on the server. Here's a quick-
and-dirty framework which is based on HttpServlet:
import java.io.IOException;
import java.util.GregorianCalendar;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TimeSensitiveServlet extends HttpServlet {
public TimeSensitiveServlet() {
super();
}
public void init() throws ServletException {
super.init();
// add any initilization code here
}
public void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException {
if( ! timeOK() )
resp.sendError( HttpServletResponse.SC_MOVED_TEMPORARILY );
// otherwise process normally
}
private boolean timeOK() {
GregorianCalendar now = new GregorianCalendar();
int dayOfWeek = 0;
int hourOfDay = 0;
dayOfWeek = now.get( GregorianCalendar.DAY_OF_WEEK );
if( dayOfWeek == GregorianCalendar.MONDAY ) {
hourOfDay = now.get( GregorianCalendar.HOUR_OF_DAY );
if( ( hourOfDay >= 10 ) && ( hourOfDay < 12 ) )
return( false );
}
else if( dayOfWeek == GregorianCalendar.FRIDAY ) {
hourOfDay = now.get( GregorianCalendar.HOUR_OF_DAY );
if( ( hourOfDay >= 14 ) && ( hourOfDay < 16 ) )
return( false );
}
return( true );
}
}