Search This Blog

Showing posts with label Tricks. Show all posts
Showing posts with label Tricks. Show all posts

Saturday, 15 March 2014

Stop Application that you don't want to run on System Startup in Windows

Steps :

1. Go to Run or press (Windows + r)
2.then type msconfig
3.go on startup tzb

4.and deselect all apps that u dont wanna run at start up..



Thank you

Wednesday, 8 January 2014

File Upload in JSP

A JSP can be used with an HTML form tag to allow users to upload files to the server. An uploaded file could be a text file or binary or image file or any document.

Creating a File Upload Form:

The following HTM code below creates an uploader form. Following are the important points to be noted down:
  • The form method attribute should be set to POST method and GET method can not be used.
  • The form enctype attribute should be set to multipart/form-data.
  • The form action attribute should be set to a JSP file which would handle file uploading at backend server. Following example is using uploadFile.jsp program file to upload file.
  • To upload a single file you should use a single <input .../> tag with attribute type="file". To allow multiple files uploading, include more than one input tags with different values for the name attribute. The browser associates a Browse button with each of them.
 
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="UploadServlet" method="post"
                        enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
This will display following result which would allow to select a file from local PC and when user would click at "Upload File", form would be submitted along with the selected file:
 
File Upload: 
Select a file to upload: 
 
 

 
 

 
NOTE: Above form is just dummy form and would not work, you should try above code at your machine to make it work.

Writing Backend JSP Script:

First let us define a location where uploaded files would be stored. You can hard code this in your program or this directory name could also be added using an external configuration such as a context-param element in web.xml as follows:
 
<web-app>
....
<context-param> 
    <description>Location to store uploaded file</description> 
    <param-name>file-upload</param-name> 
    <param-value>
         c:\apache-tomcat-5.5.29\webapps\data\
     </param-value> 
</context-param>
....
</web-app>
Following is the source code for UploadFile.jsp which can handle multiple file uploading at a time. Before proceeding you have make sure the followings:
  • Following example depends on FileUpload, so make sure you have the latest version ofcommons-fileupload.x.x.jar file in your classpath. You can download it fromhttp://commons.apache.org/fileupload/.
  • FileUpload depends on Commons IO, so make sure you have the latest version of commons-io-x.x.jar file in your classpath. You can download it from http://commons.apache.org/io/.
  • While testing following example, you should upload a file which has less size than maxFileSizeotherwise file would not be uploaded.
  • Make sure you have created directories c:\temp and c:\apache-tomcat-5.5.29\webapps\data well in advance.
<%@ page import="java.io.*,java.util.*, javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.*" %>
<%@ page import="org.apache.commons.io.output.*" %>

<%
   File file ;
   int maxFileSize = 5000 * 1024;
   int maxMemSize = 5000 * 1024;
   ServletContext context = pageContext.getServletContext();
   String filePath = context.getInitParameter("file-upload");

   // Verify the content type
   String contentType = request.getContentType();
   if ((contentType.indexOf("multipart/form-data") >= 0)) {

      DiskFileItemFactory factory = new DiskFileItemFactory();
      // maximum size that will be stored in memory
      factory.setSizeThreshold(maxMemSize);
      // Location to save data that is larger than maxMemSize.
      factory.setRepository(new File("c:\\temp"));

      // Create a new file upload handler
      ServletFileUpload upload = new ServletFileUpload(factory);
      // maximum file size to be uploaded.
      upload.setSizeMax( maxFileSize );
      try{ 
         // Parse the request to get file items.
         List fileItems = upload.parseRequest(request);

         // Process the uploaded file items
         Iterator i = fileItems.iterator();

         out.println("<html>");
         out.println("<head>");
         out.println("<title>JSP File upload</title>");  
         out.println("</head>");
         out.println("<body>");
         while ( i.hasNext () ) 
         {
            FileItem fi = (FileItem)i.next();
            if ( !fi.isFormField () ) 
            {
            // Get the uploaded file parameters
            String fieldName = fi.getFieldName();
            String fileName = fi.getName();
            boolean isInMemory = fi.isInMemory();
            long sizeInBytes = fi.getSize();
            // Write the file
            if( fileName.lastIndexOf("\\") >= 0 ){
            file = new File( filePath + 
            fileName.substring( fileName.lastIndexOf("\\"))) ;
            }else{
            file = new File( filePath + 
            fileName.substring(fileName.lastIndexOf("\\")+1)) ;
            }
            fi.write( file ) ;
            out.println("Uploaded Filename: " + filePath + 
            fileName + "<br>");
            }
         }
         out.println("</body>");
         out.println("</html>");
      }catch(Exception ex) {
         System.out.println(ex);
      }
   }else{
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet upload</title>");  
      out.println("</head>");
      out.println("<body>");
      out.println("<p>No file uploaded</p>"); 
      out.println("</body>");
      out.println("</html>");
   }
%>
Now try to upload files using the HTML form which you created above. When you would try http://localhost:8080/UploadFile.htm, it would display following result which would help you uploading any file from your local machine.
 
File Upload: 
Select a file to upload: 
 
 

 
 
If your JSP script works fine, your file should be uploaded in c:\apache-tomcat-5.5.29\webapps\data\ directory.

Ref. => javatpoint.com

Friday, 2 August 2013

Hiding Disk Completley

The following trick will enable you to hide any volume or disk you want for the sake of your privacy:-



follow the given steps :-
1. click on start.
2. select run.
3.Now type cmd.

(this will open a command prompt)
4.type the command DISKPART
5.now type LIST VOLUME
6.now we have to select the drive we want to hide
for example : SELECT VOLUME 3
7. type the command now REMOVE LETTER E
(as in case of volume 3)

Boom .
the volume will become invisible when you restart your computer.

To get the volume back to visible state.
follow the steps 1 to 6 again :
and in the 7th step write ASSIGN instead of REMOVE

I tried this on Window7- 32 bit OS

Friday, 5 July 2013

Installing the JDK and Setting the Environment Variables

Installing the JDK and Setting the Environment Variables

Want to get started with Java and set up your computer for Java, then this post is for you only. Every Java programmer I know starts off with writing the Java programs in any text editor such Notepad and compile and run it using Java tools on command line. But to make sure all goes well, you must need to install Java properly and Set up the environment variables for Java. 

Installing the Java 2 SDK (or JDK)

If you don’t have the Java 2 SDK(Software Development Kit) or simply JDK installed on your system, Follow these steps to install the JDK on your system:
1. Download the latest Java SDK version from the Oracle official site.

2. Now browse the jdk setup file on your computer and double-click on the setup file to open it. Now follow the on screen instructions to install the JDK on your system. JRE is also installed along with the JDK.
3. You can check if the JDK has been correctly installed or not by looking in the C:\Program Files\Java\. You must see the jdk1.6.0_26 folder and jre1.6.0_26 folder in it. 1.6.0_26 is the version of the jdk and it can be different depending upon which version did you download from the site.
4. Now you have successfully installed the JDK, the next step is to set the Environment Variables for your Java (JDK).

Setting up the Environment Variables


1. Right click on My Computer and click on “Properties”. Then in 
the Computer Properties window, on the left panel click on the “Advanced System Settings”, this will open the new “System Properties window.”
2. Go to Advanced tab and right down the window, click on the “Environment Variables”.
3. Now in the Environment Variables box, either you can set the variables for local user or for System variables. Local variables will only work for the current user and the System Variables will work for all the users.
4. Now for creating the variable for System Variables so that all the user can use the jdk, Find the “Path” variable in the list and click on Edit button.
5. Now place the ; followed by the path to the bin folder inside your jdk. For example  ";C:\Program Files\Java\jdk1.6.0_07\bin "
6. For local variable, you must create the PATH variable by pressing “New” button and setting its value as " ;C:\Program Files\Java\jdk1.6.0_07\bin; "
7. Now in the local variables, create a New variable “classpath” and set its value to “.” i.e. a single dot.
8. Now you are done and all ready to use the jdk for creating the java applications.

Need for Setting Environment Variables

Need for setting PATH variable:
Setting the PATH variable enables the user to use the java tools given in the bin folder from any directory on your system.
If you don’t set this variable, you can only access those tools from the bin directory only.

Need for Setting the CLASSPATH variable:
Setting the CLASSPATH variable enables your class definition to be found across all the directories. If you don’t set this variable, the program source will compile fine but will show the exception at run time that class definition not found.
So by setting the classpath variable to “.” ensures that current working directory is included in the list to found the class definition.