Archive for July, 2008

Getting a value from scriptlet to javascript

July 16, 2008

Getting value from a scriptlet into javascript is pretty simple. However the otherway round which means getting a value from a scriptlets into javascript may not be too simple.
You could probably have a hidden parameter, have its

value = <%=request.getParameter(“value”) %>

and how this request parameter is going to get populated is, when you have the jsp submit the request to itself, i.e., have the action = to the same jsp page. For submitting the page to another action, you will have to write a submitForm() method and have it populated with this.form.action=youraction and then submit it.
Now on to the main topic, to get a value from scriptlet into javascript you could :

String a = “abc”;

Then make a hidden element in our good old HTML

<input type=”hidden” name=”testa” id=”testa” value=<%= a%> >

In the javascript where you want to fetch the value, you can do a


thats all.


Date Validity Check

July 9, 2008

This logic can be used to check validty of date in date month year format :

boolean checkDate(int mm, int dd, int yy){
boolean validDate = false;
if((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && yy > 2000 ){ //this means the month has 31 days fro sure
if(dd>0 && dd 0 && dd 2000)){
validDate = true;
}else if(mm == 2)
validDate = ((yy%4 ==0)&& (dd>0 && dd0 && dd<29))? true: false; //figuring out leap year
validDate = false;

return validDate;