I have a calendar program in jsp. Program name cal.jsp. The animate.
js file is a scripting file. I am using mysql as database. Holiday is the table name, HolidayDate is of Date datatype, Description is of varchar(50) datatype. In the below program, i am not able to get some of the buttons properly. If you run this program, u can know what i am trying to say.
Another thing is, am not able to insert the date, as the date field supported in mysql is of type year-month-date(0000-00-00). so am not able to insert the data in database. i have given the servername, databasename, username,password in the original code.
cal.jsp
<%@page import="java.sql.*, java.util.*, java.text.*" %>
<%@page import="java.sql.Connection, java.sql.DriverManager,java.sql.ResultSet,java.sql .SQLException " %>
<html>
<head>
<title>Print a month page.</title>
</head>
<script language="JavaScript1.2" fptype="dynamicanimation" src="Scripts/animate.
js">
</script>
<body bgcolor="#FFECFF">
<FORM NAME="MYCALEND" method=post action="cal.jsp">
<input type="text" name="MYCURRDATE" value="">
<%!
///////////////// DATA BASE Connectivity Codes //////////////////////
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
PreparedStatement PREPstmt1;
PreparedStatement PREPstmt2;
%>
<%
response.setContentType("text/html");
try
{
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);
String serverName = " ";
String mydatabase = " ";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
String username = " ";
String password = " ";
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
}
catch(Exception e)
{
%>
<h2> <%= e %> </h2>
<%
}
Calendar c = Calendar.getInstance();
boolean yyok = false;
int yy = 0, mm = 0, ALflag=0, flaUP=0;
String MyFullDate;
String yyString = String.valueOf(c.get(Calendar.YEAR));
String STyear = request.getParameter("year");
if (STyear!=null) { yyString=STyear; }
if (yyString != null && yyString.length() > 0)
{
try
{
yy = Integer.parseInt(yyString);
yyok = true;
}
catch (NumberFormatException e)
{
out.println("Year " + yyString + " invalid" );
}
}
if (!yyok) yy = c.get(Calendar.YEAR);
mm = c.get(Calendar.MONTH);
///////////////////////////For MENU Box//////////////////////////////////////
String VVff = request.getParameter("MYCURRDATE");
String MEMrec = request.getParameter("MEMOTXT1");
String DATrec = request.getParameter("DateText1");
String MyMEMOtxt="";
try{
if(!VVff.equals(""))
{
%>
<table style="position:absolute; border-collapse:collapse; left:150; top:150" border="2" cellpadding="0" cellspacing="0" bordercolor="#CC66FF" width="255" height="250">
<tr>
<td width="248" height="1" bgcolor="#CC66FF">
MEMO</td>
<td width="26" height="1" bgcolor="#CC66FF" align="center">
<input type="submit" value="X" name="B2" style="width:25; border-style: solid; border-width: 0; font-family:Arial; font-size:10pt; font-weight:bold; color:#FFFF00; background-color:#9900CC"></td>
</tr>
<tr>
<td width="275" height="193" align="center" bgcolor="#CCCCFF" colspan="2"><p>
Date:
<input type="text" name="DateText1" value="<%=VVff%>" size="25">
<%
try
{
rs = stmt.executeQuery("select * from Holiday");
while(rs.next())
{
if(VVff.equals(rs.getString("HolidayDate")))
{
MyMEMOtxt=rs.getString("Description");
}
}
}
catch(Exception e)
{
out.println("<h1 style='position:absolute; top:200; left:1'>" + e + "</h1>");
}
%>
<textarea rows="9" name="MEMOTXT1" cols="25" style="border:1px solid #CC66FF; "><%=MyMEMOtxt%></textarea></p>
<p>
<input type="submit" value="Save" name="SaveBut1" style="text-align: center"></p>
</td>
</tr>
</table>
<%
}
else
{
try
{
rs = stmt.executeQuery("select * from Holiday");
while(rs.next())
{
if(DATrec.equals(rs.getString("HolidayDate")))
{
flaUP=1;
}
}
if(flaUP==1 && (!MEMrec.equals("")) && (!DATrec.equals(""))) ///For Modify///
{
String sqlUPD="update Holiday set Details = ? where HolidayDate = ? ";
try
{
PREPstmt2=conn.prepareStatement(sqlUPD);
PREPstmt2.setString(1, MEMrec);
PREPstmt2.setString(2, DATrec);
PREPstmt2.executeUpdate();
}
catch(Exception e)
{
out.println("<h1 style='position:absolute; top:200; left:1'>" + e + "</h1>");
}
flaUP=0;
}
else if(flaUP==1 && MEMrec.equals("") && (!DATrec.equals(""))) ///For Delete///
{
try
{
stmt.executeUpdate("delete from Holiday where HolidayDate = '" + DATrec + "'");
}
catch(Exception e)
{
out.println("<h1 style='position:absolute; top:200; left:1'>" + e + "</h1>");
}
flaUP=0;
}
else if(flaUP==0 && (!MEMrec.equals("")) && (!DATrec.equals(""))) ///For Insert///
{
String sqlINS="insert into Holiday(HolidayDate, Description) VALUES (?, ?)";
try
{
PREPstmt1=conn.prepareStatement(sqlINS);
PREPstmt1.setString(1, DATrec);
PREPstmt1.setString(2, MEMrec);
PREPstmt1.executeUpdate();
}
catch(Exception e)
{
out.println("<h1 style='position:absolute; top:200; left:1'>" + e + "</h1>");
}
}
else
{
}
}
catch(Exception e)
{
}
}
}
catch(Exception e)
{
}
/////////////////////For Calendar Generation////////////////////////////
%>
<table align="center">
<tr><td>
Enter Year : <select name="year">
<%
for(int i=2000;i<=2015;i++)
{
if(i==Integer.parseInt(yyString))
{
%>
<OPTION SELECTED= <%=i%> > <%=i%> </option>
<%
}
else
{
%>
<OPTION VALUE= <%=i%> > <%=i%> </option>
%>
<%
}
}
%>
</select>
<input type=submit value="Display">
</td></tr>
</table>
<%!
String[] months = {
"January","February","March",
"April","May","June",
"July","August","September",
"October","November","December"
};
int dom[] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
};
%>
<%
int leadGap = 0;
%>
<table border="2" cellpadding="10" cellspacing="0" width="100" align="center" bgcolor="#BBDDFF" style="border-collapse:collapse" bordercolor="#46A3FF"">
<%
int aa=-1;
GregorianCalendar calendar =null;
for(int j=0;j<12;j++)
{
calendar = new GregorianCalendar(yy, j, 1);
int row = 1 ;
row = row + j;
aa++;
if(aa==3)
{
aa=0;
out.println("<tr></tr>");
}
%>
<td valign=top>
<table>
<colgroup span="7" style="color:#FF0000;">
</colgroup>
<tr align="center">
<th colspan=7>
<%= months[j] %>
<%= yy %>
</th>
</tr>
<tr bgcolor="#46A3FF" bordercolor="#46A3FF">
<td>Sun<td>Mon<td>Tue<td>Wed<td>Thu<td>Fri<td>Sa t</td>
</tr>
<%
leadGap = calendar.get(Calendar.DAY_OF_WEEK)-1;
int daysInMonth = dom[j];
if (calendar.isLeapYear(calendar.get(Calendar.YEAR)) && j == 1)
++daysInMonth;
%>
<tr>
<%
for (int h = 0; h < leadGap; h++)
{
out.print("<td> ");
}
for (int h = 1; h <= daysInMonth; h++)
{
out.print("<td align='right'>");
MyFullDate = h + "-" + months[j] + "-" + yyString;////To get "Full Date" as dd-mmmm-yyyy/////
/////////Database Check for dates with memo/////////////
rs = stmt.executeQuery("select * from Holiday");
while(rs.next())
{
if(rs.getString("HolidayDate").equals(MyFullDate))
{
ALflag=1;
}
}
if(ALflag!=1)
{
//////////
%>
<input type="submit" value="<%=h%>" name="<%=MyFullDate%>" style="width:30; font-family:Verdana; font-weight:normal; border-style: outset; border-width:0; background-color:#DDEEFF" dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="width:30; font-family:Verdana; font-weight:normal; border-style: outset; border-width:0; background-color:#CC99FF" onmouseover="MYCALEND.MYCURRDATE.value = '<%=MyFullDate%>'; rollIn(this)" onmouseout="MYCALEND.MYCURRDATE.value =''; rollOut(this)" language="Javascript1.2">
<%
}
else
{
ALflag=0;
%>
<input type="submit" value="<%=h%>" name="<%=MyFullDate%>" style="width:30; font-family:Verdana; font-weight:normal; border-style: outset; border-width:0; background-color:green" dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="width:30; font-family:Verdana; font-weight:normal; border-style: outset; border-width:0; background-color:#CC99FF" onmouseover="MYCALEND.MYCURRDATE.value = '<%=MyFullDate%>'; rollIn(this)" onmouseout="MYCALEND.MYCURRDATE.value =''; rollOut(this)" language="Javascript1.2">
<%
}
out.print("</td>");
if ((leadGap + h) % 7 == 0)
{
out.println("<tr>");
out.println("</tr>");
}
}
%>
</tr>
</table>
<%
}
%>
</table>
<%
PREPstmt1.close();
PREPstmt2.close();
rs.close();
stmt.close();
conn.close();
%>
</FORM>
</body>
</html>
The animate.
js is inside folder called scripts, and the animate.
js contains javascript tags. If you want for checking that, i will send.
Please check my code and help me with the code