tag:blogger.com,1999:blog-27299091418546481422024-03-05T01:13:50.952-08:00Tech WorldGnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-2729909141854648142.post-65122325831030124292019-11-05T08:26:00.002-08:002019-11-05T08:26:37.536-08:00Unknown failure (at android.os.Binder.execTransact(Binder.java:674)) Error while Installing APKs<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
I had this issue when I was trying to run the android application from android studio.<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>Unknown failure (at android.os.Binder.execTransact(Binder.java:674))
Error while Installing APKs
</code></pre>
<br />
<br />
This issue occurs because of android's Instant run feature. You need to disable this feature to overcome this issue.<br />
<br />
<b>To disable Instant Run:</b><br />
<br />
<br />
<ol style="text-align: left;">
<li>Open the Settings or Preferences dialog. (For Mac, Android Studio -> Preferences)</li>
<li>Navigate to Build, Execution, Deployment > Instant Run.</li>
<li>Uncheck the box next to Enable Instant Run.</li>
</ol>
<br />
<div>
<br /></div>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-67268101897146663712019-11-02T03:30:00.001-07:002019-11-02T03:34:35.716-07:00Python AttributeError: 'module' object has no attribute 'strptime'<div dir="ltr" style="text-align: left;" trbidi="on">
This type of error occurs when the strptime method called on module instead of class:
<br />
<br />
If your import statement is like below :<br />
<br />
<pre class="lang-py prettyprint prettyprinted" style="background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="kwd" style="border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">import</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> datetime</span></code></pre>
<div style="border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
<span style="font-family: inherit; font-style: inherit; font-weight: inherit;">Then you need to access strptime method like below:</span></div>
<pre class="lang-py prettyprint prettyprinted" style="background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">datetime</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">datetime</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">strptime</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">date</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"%Y-%m-%d"</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">)</span></code></pre>
<div style="border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
to access the strptime method. Or, you could change the import statement to this:</div>
<pre class="lang-py prettyprint prettyprinted" style="background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #000000; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="kwd" style="border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">from</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> datetime </span><span class="kwd" style="border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">import</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> datetime</span></code></pre>
<div style="border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
and access it as you are.</div>
<div style="border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
The people who made the <a href="https://docs.python.org/3/library/datetime.html" rel="noreferrer" style="border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">datetime</code> module</a> also named their <a href="https://docs.python.org/3/library/datetime.html#available-types" rel="noreferrer" style="border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">class <code style="background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">datetime</code></a>:</div>
<pre class="lang-py prettyprint prettyprinted" style="background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="com" style="border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">#module class method</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
datetime</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">datetime</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">strptime</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">date</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"%Y-%m-%d"</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">)</span></code></pre>
Ref: https://stackoverflow.com/questions/19480028/attributeerror-datetime-module-has-no-attribute-strptime
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-25998785396962705332018-01-03T02:54:00.002-08:002018-01-03T02:57:07.054-08:00Android Open Phone Dialer from Code<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
There are Two ways to achieve it.<br />
<br />
<b> 1) Have to start the dialer via code, without user interaction. </b><br />
<br />
You need Action_Dial, use below code it will open Dialer with number specified.<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);
</code></pre>
<br />
The 'tel:' prefix is required, otherwhise the following exception will be thrown:<br />
<br />
<i>java.lang.IllegalStateException</i>: Could not execute method of the activity. Action_Dial doesn't require any permission. If you want to initiate the call directly without user's interaction , You can use action Intent.ACTION_CALL.<br />
<br />
In this case, you must add the following permission in your AndroidManifest.xml:<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><uses-permission android:name="android.permission.CALL_PHONE">
</uses-permission></code></pre>
<br />
<b>2) Have user to click on Phone_Number string and start the call. </b></div>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>android:autoLink="phone"
</code></pre>
<br />
You need to use TextView with below property.<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>android:autoLink="phone" android:linksClickable="true"
</code></pre>
<br />
This is how you can open EditText label assigned number on dialer directly.<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><TextView
android:id="@+id/phoneNumber"
android:autoLink="phone"
android:linksClickable="true"
android:text="+91 22 2222 2222"
/>
</code></pre>
Ref: https://stackoverflow.com/questions/11699819/how-do-i-get-the-dialer-to-open-with-phone-number-displayed</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-53762364487632146332017-12-23T04:23:00.003-08:002017-12-23T04:24:55.487-08:00Apply Border color to button on Android <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Use the <code><stroke>
</code> element. Add this xml file in res/drawable folder as button_border.xml: <br />
<br />
<stroke><br /></stroke>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#00FF00"
android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#ffffff" />
</shape>
</code></pre>
<div>
<br /></div>
then call this by in layout file<br />
<div>
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/button_border"
android:text="Button"
/>
</code></pre>
</div>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-1115522435688818752017-12-23T03:37:00.000-08:002017-12-23T03:37:13.022-08:00Forcing “portrait” orientation mode for android application<div dir="ltr" style="text-align: left;" trbidi="on">
Adding following code segment in AndroidManifest file for each activity, we can force the android application to work only in portrait mode.<br />
<br />
Note: Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
</code></pre>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-85403557128457079352017-12-18T02:43:00.001-08:002017-12-18T02:43:41.050-08:00Java Interview Question: HashSet vs HashMap<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<b>HashSet</b></h3>
<div style="text-align: left;">
</div>
<ol>
<li>HashSet class implements the Set interface</li>
<li>In HashSet, we store objects(elements or values) e.g. If we have a HashSet of string elements then it could depict a set of HashSet elements: {“Hello”, “Hi”, “Bye”, “Run”}</li>
<li>HashSet does not allow duplicate elements that mean you can not store duplicate values in HashSet.</li>
<li>HashSet permits to have a single null value.</li>
<li>HashSet is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly. </li>
</ol>
<br />
<h3 style="text-align: left;">
HashMap</h3>
<br />
<ol style="text-align: left;">
<li>HashMap class implements the Map interface</li>
<li>HashMap is used for storing key & value pairs. In short, it maintains the mapping of key & value (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This is how you could represent HashMap elements if it has integer key and value of String type: e.g. {1->”Hello”, 2->”Hi”, 3->”Bye”, 4->”Run”}</li>
<li>HashMap does not allow duplicate keys however it allows having duplicate values.</li>
<li>HashMap permits single null key and any number of null values.</li>
<li>HashMap is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly. </li>
</ol>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-86627928684405271072017-12-15T05:14:00.001-08:002017-12-15T05:14:50.473-08:00How to handle HTTP Header related issue in Apache<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
By following below steps you can suppress following HTTP Header related security issues in web applications those are hosted in apache web server.<br />
<ul style="text-align: left;">
<li>Web Browser XSS Protection Not Enabled</li>
<li>X-Frame option Header not set</li>
<li>X-Content-Type-Options header missing </li>
<li>Incomplete or No Cache-control and Pragma HTTP Header Set</li>
</ul>
<br />
<div>
<br /></div>
<div>
These issues can be handled by placing following lines in httpd.conf of apache web server.</div>
<div>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>Header set X-XSS-Protection “1; mode=block”
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always append X-Frame-Options DENY
Header set X-Content-Type-Options nosniff
Header set Content-Security-Policy "default-src 'self';"
</code></pre>
</div>
<div>
<br />
<br />
For this mod_hedaers module also need to be enabled. so uncomment the following Load Module line:<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>LoadModule headers_module modules/mod_headers.so
</code></pre>
<br />
<br />
Now doing security audit test again, you can see these issues are handled properly. </div>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-61213640572585743392017-12-15T05:00:00.002-08:002017-12-15T05:15:11.540-08:00Handling HTTP Header related security issues in Tomcat 8 web applications<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "calibri"; font-size: 12pt; font-weight: 700; vertical-align: baseline;"><br /></span> <span style="font-family: "calibri"; font-size: 12pt; font-weight: 700; vertical-align: baseline;">The following issues are the commonly occurs in security audit report of any java web applications</span><br />
<br />
<ul style="text-align: left;">
<li>Web Browser XSS Protection Not Enabled</li>
<li>X-Frame option Header not set</li>
<li>X-Content-Type-Options header missing </li>
<li>Incomplete or No Cache-control and Pragma HTTP Header Set</li>
</ul>
<div>
<br /></div>
<div>
Tomcat 8 provides, support for following http header </div>
<div>
<br /></div>
<br />
<div>
<ul style="text-align: left;">
<li>X-Frame-Options – to prevent clickjacking attack</li>
<li>X-XSS-Protection – to avoid cross-site scripting attack</li>
<li>X-Content-Type-Options – block content type sniffing</li>
<li>HSTS – add strict transport security</li>
</ul>
<div>
<br /></div>
</div>
<div>
To utilize this option we need to follow simple steps. Just uncomment the following lines in Tomcat's web.xml files (<tomcat_home>\conf\web.xml).</tomcat_home></div>
<div>
<br /></div>
<div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><filter>
<filter-name>HeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</code></pre>
</div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 72pt; margin-top: 0pt;">
<span style="font-family: "calibri"; font-size: 10pt; vertical-align: baseline;"><br /></span></div>
<div>
Remember it is not applications individual web.xml files. it is tomcat's web.xml. after uncommenting these lines. restart the tomcat and redo the security audit. you can see the issues are handled.</div>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-12794089649642696352017-10-13T00:32:00.001-07:002017-10-13T00:38:05.273-07:00'gradle' is not recognized as an internal or external command<div dir="ltr" style="text-align: left;" trbidi="on">
Following steps need to be followed for fixing: "<b><i>'gradle' is not recognized as an internal or external command</i></b>" error.<br />
<br />
<ol style="text-align: left;">
<li> Download the zipped file of Gradle from <a href="https://services.gradle.org/distributions/gradle-2.8-all.zip">https://services.gradle.org/distributions/gradle-2.8-all.zip</a>. </li>
<li>Unzip them and place them in your Windows machine at any specific location. For e.g. “C:\Program Files\”. </li>
<li>Click on the Windows button at the left bottom of the desktop. </li>
<li>Right-click on “<i>Computer</i>” and click on “<i>Properties</i>”. This will open the Control Panel. </li>
<li>Click on “<i>Advanced System settings</i>” and then click on “<i>Environment Variables</i>” button. </li>
<li>Click on “<i>New…</i>” button under the “<i>System Variables</i>” section and enter Variable name as ‘<b><i>GRADLE_HOME</i></b>’. </li>
<li>Provide the path of the Gradle file as Variable value, i.e.<i> C:\Program Files\gradle-2.8 </i></li>
<li>Click OK. </li>
<li>Select “path” variable under the “<i>System Variables</i>” section and click on “<i>Edit</i>” button. </li>
<li>Go to the end of variable value and add “<i>;%GRADLE_HOME%\bin</i>” and click on “OK” button. </li>
<li>Press “<i>Windows + R</i>” and type ‘<i>cmd</i>’. Click OK. </li>
<li>Type the command “<i>gradle –v</i>” on the command prompt. </li>
<li>Now the screen displays the version of the Gradle. This means that the Gradle is successfully configured on the given Windows machine.</li>
</ol>
</div>
Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-15307780868780124852011-03-26T03:38:00.001-07:002011-03-26T03:38:44.750-07:00Escape Special chracters in javaFollowing code escaps the special meaning of characters before showing in XML or in view<br />
<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> public static String escapeText(String s) {
if (s.indexOf('&') != -1 || s.indexOf('<') != -1
|| s.indexOf('>') != -1 || s.indexOf('"') != -1
|| s.indexOf('\'') != -1 ) {
StringBuffer result = new StringBuffer(s.length() + 6);
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '&') result.append("&amp;");
else if (c == '<') result.append("&lt;");
else if (c == '"') result.append("&quot;");
else if (c == '\'') result.append("&apos;");
else if (c == '>') result.append("&gt;");
else result.append(c);
}
return result.toString();
}
else {
return s;
}
}
</code></pre>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-55476791086288329122011-01-18T23:12:00.000-08:002011-01-18T23:15:09.261-08:00HTML 5 logo unveiled by W3C<a href="http://www.w3.org/html/logo/downloads/HTML5_Logo_128.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="HTML5" border="0" src="http://www.w3.org/html/logo/downloads/HTML5_Logo_128.png" /></a>Imagination, meet implementation. HTML5 is the cornerstone of the W3C's open web platform; a framework designed to support innovation and foster the full potential the web has to offer. Heralding this revolutionary collection of tools and standards, the HTML5 identity system provides the visual vocabulary to clearly classify and communicate our collective efforts.<br />
<br />
<br />
W3C unveiled today an HTML5 logo, a striking visual identity for the open web platform. W3C encourages early adopters to use HTML5 and to provide feedback to the W3C HTML Working Group as part of the standardization process. Now there is a logo for those who have taken up parts of HTML5 into their sites, and for anyone who wishes to tell the world they are using or referring to HTML5, CSS, SVG, WOFF, and other technologies used to build modern Web applications. The logo home page includes a badge builder (which generates code for displaying the logo), a gallery of sites using the logo, links for buying an HTML5 T-shirt, instructions for getting free stickers, and more. The logo is available under "Creative Commons 3.0 By" so it can be adapted by designers to meet their needs.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3e-OPwoC0_2dfBHDobzv3u1MUAsOXn_Peuhy0CIfvH2ge84P4r94M8liPvTXZJoPwYZSoD4iW8HWlWi8-feMq5Avvo68Y8KcWDDV5Z9iURkvHXCw9KRIbRc5D_KhZuzrIVa-IMrIUbRNu/s1600/html5-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="270" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3e-OPwoC0_2dfBHDobzv3u1MUAsOXn_Peuhy0CIfvH2ge84P4r94M8liPvTXZJoPwYZSoD4iW8HWlWi8-feMq5Avvo68Y8KcWDDV5Z9iURkvHXCw9KRIbRc5D_KhZuzrIVa-IMrIUbRNu/s400/html5-logo.png" width="400" /></a></div>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-51070462671998606782011-01-05T02:32:00.000-08:002011-01-05T02:32:00.147-08:00Updating(Replace) anchor href values in a webpageUsing the jquery One can update attribute values of html elements in a simple steps .<br />
The following jquery script will update the href value of all the anchor links those<br />
available in a web page to a static url http://www.tecrocks.com.<br />
<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>$('a[href]').attr('href', 'http://www.tecrocks.com');
</code></pre><br />
This will be helpful for the situation like displaying the webpage content in a custom print preview page like so.<br />
The following block will update all the href value in page without considering the element of the href value.<br />
<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>$('[href]').each(function () {
$(this).attr('href', 'http://www.tecrocks.com');
});
</code></pre><br />
Using *= filders with in [] we can filter the href url's.Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-61091332456168252062011-01-04T00:01:00.000-08:002011-01-04T00:02:31.488-08:00Truncating(Clip) Excess text with Ellipsis in HTML5 Text-overflow property in CSS gives the way to deal with the clipped text when the actual text content size is exceed the container box.<br />
'text-overflow' css attribute allows the text to be clipped when its exceed the allowed display area by setting text-overflow value as ellipsis, it will display ellipsis( three periods) following the clipped text.<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>.cliptext
{
color: #eee;
border: 1px solid #000000;
overflow: hidden;
width: 100%;
text-overflow: ellipsis;
white-space: nowrap;
}
</code></pre><br />
To get this ellipsis effect when the content fall outside the box you may need to set the boxs overflow property to hidden or scroll and white-space property to 'nowrap'.<br />
<br />
If you have any comments or suggestions in setting ellipsis please leave a comment.Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com1tag:blogger.com,1999:blog-2729909141854648142.post-43036009057957575922010-11-24T03:45:00.000-08:002010-11-24T03:46:47.326-08:00Generate a random alpha-numeric string in JavaBy combinig use of Char array that having alphabets and numbers are an string of alphanumberic characters we can generate random alpha numberic strings in java.here is the exampls code that generate random alpha numberic string for the given length.<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code> /**
* Generates alpha numeric random number for the given length.
* for this it accounts lowercase alpha characters(a-z) and numbers(0-9)
* @param length length of the alpha numeric random to be generated.
* @return resulting random alpha numeric string for the given length.
*/
public static String getAlphaNumbericRandom(int length) {
//include lower case alpha(a-z) and numbers(0-9)
String chars = "abcdefghijklmnopqrstuvwxyz0123456789";
int numberOfCodes = 0;//controls the length of alpha numberic string
String code = "";
while (numberOfCodes < length) {
char c = chars.charAt((int) (Math.random() * chars.length()));
code += c;
numberOfCodes++;
}
System.out.println("Code is :" + code);
return code;
}
</code></pre><br />
If we want to create 6 digit apha numberic random means we have call getAlphaNumbericRandom methods as<br />
<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>getAlphaNumbericRandom(6);
</code></pre>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-52707497843039289922010-11-23T03:06:00.000-08:002011-04-30T02:08:03.378-07:00Replace all characters with in two tags using regular expressions<div dir="ltr" style="text-align: left;" trbidi="on"><a href="http://www.tecrocks.com/2011/04/using-regular-expressions-replace-all.html">Replace all characters with in two tags using regular expressions</a> Moved to <a href="http://www.tecrocks.com/">www.tecrocks.com</a> in the following path<br />
<span class="Apple-style-span" style="color: #554646; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 20px;"></span><br />
<h3 class="post-title" style="border-bottom-color: rgb(179, 179, 179); border-bottom-style: solid; border-bottom-width: 2px; color: #cc0000; font: normal normal normal 165%/normal Georgia, Utopia, 'Palatino Linotype', Palatino, serif; line-height: 1.4em; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 2px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; text-decoration: none;"><a href="http://www.tecrocks.com/2011/04/using-regular-expressions-replace-all.html" style="color: #cc0000; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">Replace all characters with in two tags using Regular expressions in Java</a></h3></div>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-75443389388531906052010-10-20T13:13:00.000-07:002011-01-05T20:57:12.480-08:00Format Source Code for Blogging<style type="text/css">
pre.source-code {
font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;
color: #000000;
background-color: #eee;
font-size: 12px;
border: 1px dashed #999999;
line-height: 14px;
padding: 5px;
overflow: auto;
width: 100%
}
p.warning {
color: #000000;
background-color: #FFB6C1;
font-size: 12px;
border: 3px double #333333;
line-height: 14px;
padding: 5px;
overflow: auto;
width: 100%
}
</style> <br />
Here is the interface to change your source code for put in blogging environments. This escapes the html tags so you can display your source codes in blogs<br />
<script language="JavaScript">
<!--
var Color= new Array();
Color[1] = "ff";
Color[2] = "ee";
Color[3] = "dd";
Color[4] = "cc";
Color[5] = "bb";
Color[6] = "aa";
Color[7] = "99";
function fadeIn(where) {
if (where >= 1) {
document.getElementById('fade').style.backgroundColor = "#ffff" + Color[where];
if (where > 1) {
where -= 1;
setTimeout("fadeIn("+where+")", 200);
} else {
where -= 1;
setTimeout("fadeIn("+where+")", 200);
document.getElementById('fade').style.backgroundColor = "transparent";
}
}
}
function format() {
var strIn = document.getElementById("textin").value;
var strOut = null;
if ( document.getElementById("embedstyle").checked ) {
strOut = "<pre style=\"font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%\"><code>";
hideElement("style");
} else {
strOut = "<pre class=\"source-code\"><code>";
showElement("style");
}
var strOut25 = null;
var line = 1;
var strTab;
var hasVerticalPipe = false;
var j;
if ( document.getElementById("tab4").checked ) {
strTab = " ";
} else if ( document.getElementById("tab2").checked ) {
strTab = " ";
} else {
strTab = " ";
}
for ( i = 0; i < strIn.length; i++ ) {
var code = strIn.charCodeAt(i);
switch( code ) {
case 9: // tab
strOut += strTab;
break;
case 10: // line-feed
case 13:
strOut += "\n";
line += 1;
if ( line == 26 ) {
strOut25 = strOut + "[only the first 25 lines shown in this example]\n\n";
}
j = i + 1;
if ( code == 13 && j < strIn.length && strIn.charCodeAt(j) == 10 ) {
i++;
}
break;
case 34:
strOut += """;
break;
case 38:
strOut += "&";
break;
case 60:
strOut += "<";
break;
case 62:
strOut += ">";
break;
case 124: // vertical pipe (blogger modifies this)
strOut += "|";
hasVerticalPipe = true;
break;
default:
if ( code >= 32 && code <= 127 ) {
strOut += strIn.charAt(i);
} else {
strOut += "&#" + code + ";";
}
break;
} // switch
} // for
strOut += "\n</code></pre>";
var textoutelement = document.getElementById("textout")
textoutelement.value = strOut;
textoutelement.focus();
textoutelement.select();
if ( hasVerticalPipe ) {
showElement( "vert-pipe-warning" );
} else {
hideElement( "vert-pipe-warning" );
}
var resultselement = document.getElementById("results");
if ( strOut25 != null ) {
resultselement.innerHTML = strOut25;
} else {
resultselement.innerHTML = strOut;
}
fadeIn(7);
}
function onloadEvent() {
var textinelement = document.getElementById("textin");
textinelement.focus();
textinelement.select();
}
function showElement(strId) {
var ref = document.getElementById(strId);
if ( ref.style) { ref = ref.style; }
ref.display = '';
}
function hideElement(strId) {
var ref = document.getElementById(strId);
if ( ref.style) { ref = ref.style; }
ref.display = 'none';
}
//-->
</script> <br />
<br />
<form><textarea cols="50" id="textin" rows="5" wrap="off">Paste your text here.</textarea><br />
<table><tbody>
<tr> <td><button onclick="format()" type="button">Format Text</button></td> <td><br />
Tab size: <input id="tab2" name="tabsize" type="radio" />2 <input checked="true" id="tab4" name="tabsize" type="radio" />4 <input id="tab8" name="tabsize" type="radio" />8<br />
<br />
Embed Stylesheet: <input checked="true" id="embedstyle" type="checkbox" /><br />
<br />
</td> </tr>
</tbody></table><div class="step-instr" id="fade">Copy the HTML below to your clipboard. Insert the HTML of your blog or wiki.<br />
<br />
<textarea cols="50" id="textout" rows="12" wrap="off">formatted HTML will appear in here.</textarea></div></form><div id="vert-pipe-warning" style="display: none;"><div class="warning"><b>Vertival Pipe Character Warning:</b><br />
<br />
The text contains the vertical pipe character '|' which Blogger's editor may remove. Blogger's editor on the web has two edit tabs: "Edit HTML" and "Compose". The "Compose" tab will remove all | characters! Use the "Edit HTML" tab only.</div></div><div id="results"><pre class="source-code"><code>This is an example of what your text will look like.
• Tabs are converted to spaces.
• Quotes and other special characters are converted to HTML.
• Everything is enclose in HTML's 'pre' and 'code' tags.
• Style is set:
• Fixed width font.
• Shaded box.
• Dotted line border.
</code></pre></div><div id="style" style="display: none;">Example Stylesheet:<br />
<br />
<textarea cols="50" id="textout" rows="13" wrap="off"><style type="text/css"> pre.source-code { font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100% } </style></textarea> </div><br />
Source :formatmysourcecode.blogspot.comGnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-71001230153313627322010-09-08T23:38:00.000-07:002010-09-08T23:38:47.066-07:00Disable Enter key in Form tag<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Placing the following code in your page section will disable the enter key operation in text field</span></span><br />
<div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"></span></span><br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><div><br />
</div><div><pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <script type="text/javascript">
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
</script>
</code></pre></div><div>Source : http://www.webcheatsheet.com</div></span></span></div>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-47298034281271545142010-09-04T02:13:00.000-07:002010-09-04T02:13:02.486-07:00Redirect Action result to another action in struts2Using special result type in Struts-2 result we can forward one actions result to another action before forwarding it to view logic.<br />
"redirect-action" result type is used to achieve this.here is the sample code snippet to show how to redirect one actions result to another action<br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <action name="userInfo" class="UserAction">
<!-- Redirect to another namespace -->
<result type="redirect-action">
<param name="actionName">getDetails</param>
<param name="userId">${userId}</param>
</result>
</action>
</code></pre><br />
Here after finishing userInfo action getDetails action will be invoked.Here by using "Param" tags we can pass the values to the getDetails action.Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-28957189543654262752010-08-25T00:43:00.000-07:002010-08-25T01:03:37.609-07:00Displaying Current Date using JavascriptWe can get the current date using the javascript build-in functions. To get the current date we have to use<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> var dt new Date()
</code></pre><br />
in javascript.This creates one date type variable which holds all the date related informations like date,moth,year,time etc,.<br />
Displaying this in any component or in alert will give information like<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Wed Aug 25 2010 13:42:41 GMT+0530 (India Standard Time)
</code></pre><br />
There are various methods are available in javascript to get the details only what we needed from this .We can use these methods like<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> dt.getMonth();
dt.getDate();
</code></pre><br />
First one(getMonth()) gives only current month(0-11),getDate() gives the current date.Here is the sample to get MM/DD/YYYY for the current date in javascript<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> var curr_date=new Date();
var month=curr_date.getMonth()+1;
var day=curr_date.getDate();
var year=curr_date.getYear();
// Y2K compliant
if (year < 1000) year +=1900;
document.getElementById(component).value = month + "/" + day + "/" + year;
</code></pre><br />
<br />
In this the getYear() method will return non Y2K compliant year(110 for 2010 ! ) to make this Y2K complian ,we need to add 1900 with that.Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-30599639458329676382010-08-18T02:42:00.000-07:002010-08-18T02:42:34.641-07:00Creating a ZIP file in JAVAUsing ZipOutputStream and Class in java.util.zip package we can craete an zip entry for the list of files.<br />
The following gives the sample to create an zip file "outfile.zip" .This zip whill be created using the contents those given in the 'filenames' array.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: // These are the files to include in the ZIP file
2: String[] filenames = new String[]{"filename1", "filename2"};
3: // Create a buffer for reading the files
4: byte[] buf = new byte[1024];
5: try {
6: // Create the ZIP file
7: String outFilename = "outfile.zip";
8: ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
9: // Compress the files
10: for (int i=0; i<filenames.length; i++) {
11: FileInputStream in = new FileInputStream(filenames[i]);
12: // Add ZIP entry to output stream.
13: out.putNextEntry(new ZipEntry(filenames[i]));
14: // Transfer bytes from the file to the ZIP file
15: int len;
16: while ((len = in.read(buf)) > 0) {
17: out.write(buf, 0, len);
18: }
19: // Complete the entry
20: out.closeEntry();
21: in.close();
22: }
23: // Complete the ZIP file
24: out.close();
25: } catch (IOException e) {
26: }
</code></pre><br />
<span class="Apple-style-span" style="font-size: small;">Source : http://www.exampledepot.com</span>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-64028764214334268702010-08-10T00:55:00.000-07:002010-08-10T00:58:57.971-07:00Replace All in JavascriptBy Using regular expression with javascript replace function we can implement replace all functionality.here is the sample code block for javascript replace all functionlity.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <Script Language="javascript">
var str = "Javascript replace test.";
var rs = str.replace(/is/g,"");
document.write(st);
</Script>
</code></pre><br />
<br />
here /is key for case insensitive search and /g recursive searchGnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-71864773440119048222010-08-09T03:25:00.000-07:002010-08-10T00:50:36.717-07:00Printing Web pageUsing javascript methods you can print the webpage contents or portion of webpage for your likes<br />
<br />
calling window.print() method invoke the browser's print dialog.<br />
<br />
By setting appropriate styles in css classes you can hide/show particular parts of the display from printing.<br />
<br />
To enable it include print.css only on printing time, for this you have to set media to "print"<br />
so the particular css stylesheet invoked only while printing<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <link rel="stylesheet" type="text/css" href="print.css" media="print" />
</code></pre><br />
setting media as screen sets the display for browser<br />
<br />
<br />
sample print.css content<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> div { display: none; }
#yourdiv { display: block; }
</code></pre><br />
<br />
update :<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> @media print {
div.header {
display: none;
}
div.printable {
page-break-inside: avoid;
page-break-after: always;
}
}
</code></pre><br />
This will hide the div content those are not need to be printed.<br />
page-break-inside: avoid; page-break-after: always; are the two properties allign print content in a manner.Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-66670766956672356622010-08-05T04:27:00.000-07:002010-08-05T04:28:19.153-07:00Getting multiple out parameters from oracle proceduresBy using "<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17px;">DataReadQuery " when calling oracle stored procedure you can get values for multiple out parameters</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17px;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17px;">here is the code snippet one i found in net when searching for this concept</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17px;"><br />
</span><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwm3UmLH9RrKOSgSSxKLPXWMJvFkVac5_j4P4azZYWyy-Y3mBQaWTyimphogqCmm1Je1mwJRHaVdGFxDLjT_QfGmK5bEHon6tSNPIZpZA_8GDfk3qzYw4vAT3GLhoPFb3-fdeQqMdo93Qv/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> JpaEntityManager jpaEntityManager = JpaHelper.getEntityManager(em);
Session session = jpaEntityManager.getActiveSession();
StoredProcedureCall spc = new StoredProcedureCall();
spc.setProcedureName(“two_args_out”);
spc.addNamedArgument(“x”);
spc.addNamedOutputArgument(“y”);
spc.addNamedOutputArgument(“z”);
DataReadQuery query = new DataReadQuery();
query.setCall(spc);
query.addArgument(“x”);
List args = new ArrayList();
args.add(“Wouter”);
List results = (List) session.executeQuery(query, args);
DatabaseRecord record = (DatabaseRecord)results.get(0);
String y = (String) record.get(“y”);
String z = (String) record.get(“z”);
</code></pre><br />
Before this i have used ValueReadQuery to get result set from the procedure.but it doesn't help with multiple out parameters ,it returns only one.Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0tag:blogger.com,1999:blog-2729909141854648142.post-41348653250454154512010-08-03T00:55:00.000-07:002011-04-30T02:20:17.549-07:00Access Java Static Methods in Struts2 Using OGNL<div dir="ltr" style="text-align: left;" trbidi="on"><div><a href="http://tecrocks.com/access-java-static-methods--constant-ognl-struts2.html">Access Java Static Methods in Struts2 Using OGNL</a> is moved to <a href="http://tecrocks.com/access-java-static-methods--constant-ognl-struts2.html">www.tecrocks.com</a> </div></div>Gnanzhttp://www.blogger.com/profile/00970416680948244048noreply@blogger.com0