Monday, August 21, 2017

Is it possible to access struts2 variable in jsp scriptlet?/ How to use struts2 variable in jsp scriptlet?

<s:set var="jspVariable" value="%{strutsVariable}"/>

<jsp:useBean id="jspVariable" type="com.example.Object" />

<%=jspVariable%>

Friday, July 11, 2014

How to convert date format dd-mmm-yy to yyyy-mm-dd in javascript

function changeDateFormat(dateToBeFormated){
var months = {'jan': '01', 'feb': '02', 'mar': '03', 'apr': '04', 'may': '05', 'jun': '06', 'jul': '07', 'aug': '08', 'sep': '09', 'oct': '10', 'nov': '11', 'dec': '12'};
var arr = dateToBeFormated.split('-'); // split based on '-'
var year = '20'+ arr[2] ; // add '20' before year
var month = months[arr[1].toLowerCase()] ; // convert month into lower
var day = arr[0] ;
if (day < 10) day = "0" + day; // add '0' if date is less then 10.
return [year,month,day].join('-'); // join value according to format.
}

Monday, July 7, 2014

How to get the lost java file data back in eclipse which is lost by sudden power off?

sometimes when we work on eclipse and suddenly power get off and we lost the whole page data.our page get blank.
Dont get disappoint .The solution of this problem is :

right click on the blank page go to the "replace with" option then click on previous from local history and you
will get back your lost page.

Friday, May 2, 2014

How to Submit a form when enter key is pressed

Sometimes in a form we want to submit a form when we press enter key(we do not want to click the button).

For this purpose here is a simple code

Suppose we have a page as below

<div id="loginDiv" title="Registered User Sign-In">
    <h1 class="upp">Sign In</h1>
    <form action="Login.do" name="formLogin" method="post" id="formLogin">
   
            <p>Please complete these fields.</p>
            <p>
            <input name="email" type="text" placeholder="Email address" size="30"  />
            </p>
            <p>
<input name="password" type="password" placeholder="Password" size="30" />
            </p>
           
<p class="clear"></p>
<p>
<input type="button" name="login" id="login" onclick="$('#formLogin').submit()" value="Sign In" >
</p><!-- bigbut -->
</form>

</div>

The id of div is  loginDiv . So we can write the following code for capturing key press event on div.

$("#loginDiv").keypress(function(e){
 if (e.keyCode == 13){
 $('#searchForm').submit();
 }
});


above code solves this problem.

Monday, April 21, 2014

How to disable backspace button as back button in browser ?

Sometimes when we fill online form and by mistake we press the backspace button it take us to the previous page and the data filled by us get lost.so by using the following jquery code we can disable backspace button to work as back button of browser.This  code will disable baspace button as back button if we have clicked outside any input field in the browser and if focus is on textfield or textarea it will behave as usual.


<script type="text/javascript">

$(document).keydown(function(e) {
var element = e.target.nodeName.toLowerCase();
if (e.keyCode === 8) {
   if ((element != 'input' && element != 'textarea') || (element == 'input' && $(e.target).attr("type")== 'radio')|| (element == 'input' && $(e.target).attr("type")== 'checkbox')) {
       return false;
   }
}
});

</script>