Tuesday, 14 April 2020

Getting multiple checkboxes/checkbox group values in JSP.


In this post, we look that how can get the multiple checkbox/checkbox group values using JSP.

So first craete multiple checkboxes:-

<form id="" action="get_choice.jsp" method="post">

<input name='cid' type='checkbox' value='value1' />
<input name='cid' type='checkbox' value='value2' />
<input name='cid' type='checkbox' value='value3' />
<input name='cid' type='checkbox' value='value4' />

</form>

Now where we want to recieve these values (in my case it is get_choices.jsp)
In String array get these values-

String[] cid=request.getParameterValues("cid");

if(cid!=null)
{
for(int i=0;i<cid.length;i++)
{
out.print(cid[i]);
}
}

You can also store these values in different variables for further processing like-

String[] cid; String ch1,ch2,ch3;

cid=request.getParameterValues("cid");

if (cid != null)
{
for(int i=0;i<cid.length;i++)
{
if(i==0)
ch1=cid[0];
if(i==1)
ch2=cid[1];
if(i==2)
ch3=cid[2];

}
}




Friday, 14 February 2020

How to increase database file upload limit(import database file) in phpMyAdmin.

The default upload limit is 2MB to import any database in phpMyAdmin. So if have any file larger than 2MB to import, we would not be able to import the file to database.

You can increase this limit to upload any file size supported to server.

To increase file size, you have to open file php.ini

In Linux, this file can found in /etc directory.

In Windows, It can be opened by  click on WAMP server icon on Windows taskbar/ System tray.

Just click on WAMP icon -----> PHP -----php.ini






Find two entries in this file-

1.  upload_max_filesize
2.  posr_max_size

And change these values to your required file size e.g. 10M




Thursday, 13 February 2020

Error - "Forbidden : You don't have permission to acces /phpmyadmin/ on this server" on Linux server (CentOS 7).

After installing LAMP on your Linux server, if you are getting error like "Forbidden:You don't have permission to access /phpmyadmin/ on this server", then it means that you are accessing it from server ip address and it is allowed from only localhost or you are accessing it from localhost and it is allowed only from ip address. So what to do next?


Type command -

sudo gedit /etc/httpd/conf.d/phpMyAdmin.conf

You will get the phpMyAdmin.conf file and at top you will find following code

Chane the line Require ip 127.0.0.1 and Allow from 127.0.0.1 if you want to access it using localhost on local machine. If you want to access it using your system ip address  on local machine then change 127.0.0.1 to to your system ip address

<Directory /usr/share/phpMyAdmin/>
      AddDefaultCharset UTF-8
  
<IfModule mod_authz_core.c>
    # Apache 2.4
   <RequireAny>
        Require ip 127.0.0.1
        Require ip ::1
   </RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny, Allow
     Deny From All 
     Allow from 127.0.0.1
     Allow from ::1
</IfModule>
</Directory>
 
If you want to access this server from any machine then replace the above code with

<Directory /usr/share/phpMyAdmin/>
      AddDefaultCharset UTF-8

<IfModule mod_authz_core.c>
     # Apache 2.4

     <RequireAny>
       Require all granted
     </RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
     #Apache 2.2
      Order Allow, Deny
      Allow from all
      Allow from 127.0.0.1
      Allow from ::1
</IfModule>
</Directory>


Monday, 10 February 2020

Unable to access Tomcat server running on Linux from another machine.

If you have installed Tomcat server on Linux and it is working on properly on installed machine, but you are unable to access it from other machine. If both machines are connected properly but again you are unable to access this. Then you can try this method.

(If have used this on CentOS running Tomcat 9 server)

It might be problem of firewall, so please use this command-
(I suppose your Tomcat server is using port 8080, if it uses another then use that port number in command)

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent

sudo firewall-cmd --reload



Sunday, 9 February 2020

Add multiple Jar file to classpath with javac command in Java.

Look how we can add multiple or single jar file to javac command.

Example given below for adding single jar file to javac-

javac -cp "absolute_path_of_jar_file" java_file_name.java
(javac -cp "F:\tomcat\lib\servlet-api.jar" test.java)

or

javac -classpath "absolute path of jar file" java_file_name.java

( javac -classpath "F:\tomcat\lib\servlet-api.jar" test.java )

For adding multiple files -

javac -cp "absolute path of jar file1; path of jar file2" java_file_ name.java

javac -classpath "absolute path of jar file1; path of jar file2" java_file_name.java

(javac -cp "F:\tomcat\lib\servlet-api.jar;F:\tomcat\webapps\file-sharing\WEB-INF\lib\anyjar.jar" test.java)

If all jar files in a same directory then, suppose if all in lib folder then

javac -cp "c:\tomcat\webapps\project\lib\*"  java_file_name.java

(javac -cp "F:\tomcat\lib\servlet-api.jar;F:\tomcat\webapps\file-sharing\WEB-INF\lib\*" test.java)

Sunday, 31 March 2019

KVM is required to run this AVD. /dev/kvm/ device:permission denied. Grant current user access to /dvm/kvm

When I updated my Android Studio to 3.2.2 and when tried to run emulator got the problem -


After searching on internet, I found the successful solution here .

Solution is to need to install qemu-kvm. To do this run command type -

sudo apt-get install qemu-kvm

After successful installation of qemu-kvm, check the ownership of /dev/kvm, to check this, type-

ls -al /dev/kvm 

After this command you can see that kvm is under root ownership.

Now type following command to check the which user is under kvm group -

grep kvm /etc/group

This command will give output like -

kvm:x:127:

So, there is nothing after second colon (:), there should be a username after second colon.

So, to add user (your system username) to kvm group, type

sudo adduser <your_system_user> kvm

This command will add you (your system user) to the kvm group.
Once again run the command -

grep kvm /etc/group

Output may be like -

kvm:x:127:your_system_username

Now all done. Re-login/restart  is required to apply the effects.

See all steps screen shot bellow -





Saturday, 30 March 2019

Execute any command/script at system startup in Ubuntu 18.04 (LTS)

Today, after installing Ubuntu 18.04 after a long use of lower version of Ubuntu, I got there is no rc.local file in etc directory. Actually this file is used to start any script at system startup.

So, what to do if it is not available in Ubuntu 18.04?

Just create a file by typing any of given command -

sudo nano /etc/rc.local

or

sudo gedit /etc/rc.local

or

sudo cat /etc/rc.local


and paste the following text in this file -


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0



After saving this, make it executable by command -

chmod +x /etc/rc.local


Now you can paste your scripting script in this file.

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...