Important alert: (current site time 11/22/2014 8:27:19 PM EDT)
 

VB icon

Calendar Servlet

Email
Submitted on: 2/22/2004 6:37:31 AM
By: VbNick  
Level: Beginner
User Rating: By 1 Users
Compatibility: Java (JDK 1.2)
Views: 8885
author picture
(About the author)
 
     This is just a beginners' stuff. I was archiving my old files and I saw my servlet examples from Java lectures. I just wanted to post some of them, and gave a start with this piece of code. Hope beginners find it usefull. This is a servlet, written in IBM Websphere. It shows a simple calendar. It marks current date with "*", and jumps to a new line when the new week starts.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Calendar Servlet
// Description:This is just a beginners' stuff. I was archiving my old files and I saw my servlet examples from Java lectures. I just wanted to post some of them, and gave a start with this piece of code. Hope beginners find it usefull. This is a servlet, written in IBM Websphere. It shows a simple calendar. It marks current date with "*", and jumps to a new line when the new week starts.
// By: VbNick
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4097&lngWId=2//for details.//**************************************

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * @version 	1.0
 * @author Kayhan TANRISEVEN
 */
public class webStart extends HttpServlet {
	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
			 
 PrintWriter out = resp.getWriter();
 
 	
 	// construct d as current date
 	
		// d'yi su andaki tarih olarak ata
		GregorianCalendar d = new GregorianCalendar();
		int today = d.get(Calendar.DAY_OF_MONTH);
		int month = d.get(Calendar.MONTH);
		
		//set d to start date of the month
		//d'yi bu ayin basinda baslamak icin hazirla
		
		d.set(Calendar.DAY_OF_MONTH,1);
		
		int weekday = d.get(Calendar.DAY_OF_WEEK);
		
		//print heading
		//basligi yazdir
		
		out.println("Sun Mon Tue Wed Thu Fri Sat");
		
		//indent first line of calendar
		//takvimin ilk satirini bir satir iceriden baslat
		
		for (int i = Calendar.SUNDAY; i<weekday;i++)
		out.print(" ");
		
		do
		{
			
			//print day
			//gunu yazdir
			
			int day = d.get(Calendar.DAY_OF_MONTH);
			if(day<10) out.print(" ");
			out.print(day);
			
			//mark current day with *
			//su andaki tarihi * ile isaretle
			
			if (day == today)
			 out.print("* ");
			else
			 out.print(" ");
			 
			 //start new line after every Saturday
			 //her cumartesinden sonra yeni bir satira gec
			 
			 if (weekday == Calendar.SATURDAY)
			 out.println();
			 
			 //advance d to the next day
			 //d'yi bir sonraki gune ilerlet
			 
			 d.add(Calendar.DAY_OF_MONTH,1);
			 weekday = d.get(Calendar.DAY_OF_WEEK);
		}
		
		while (d.get(Calendar.MONTH) == month);
		
		//loop the exits when d is 1 of the next month
		
		//print final end of line if necessary
		
		if (weekday != Calendar.SUNDAY)
		out.println();
		
 
	}
	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	}
	/**
	* @see javax.servlet.GenericServlet#void ()
	*/
	public void init() throws ServletException {
		super.init();
	}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.