Posts

Showing posts from August, 2012

File Upload (Using Struts)

Image
Project Structure web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">   <welcome-file-list>     <welcome-file>index.jsp</welcome-file>   </welcome-file-list>   <servlet>       <servlet-name>Front Controller</servlet-name>       <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>       <init-param>               <param-name>config</param-name>               <param-value>/WEB-INF/struts-...

Spring AOP Example

It’s a simple implementation of Spring AOP. Project Contents:     File Name Use service.xml Configuration File. ServiceClass Target Class on which we will apply AOP. AdviceClass Advisor class which will be applied on target class. SeviceUtilizer It will control the overall process. service.xml   <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                    xsi:schemaLocation="http://www.springframework.org/schema/beans                     ...

MongoDB Sharding

Here A, B and C are shards respectively running on port no 20000, 20001 and 20002. mongod --shardsvr --dbpath E:\Mongo\A --port 20000 mongod --shardsvr --dbpath E:\Mongo\B --port 20001 mongod --shardsvr --dbpath E:\Mongo\C --port 20002 Configuration server is running on port no 20003. mongod --configsvr --dbpath E:\Mongo\config --port 20003 Mongos router is on port no 20005. mongos --configdb 10.15.1.208:20003 --port 20005 Now connect to the mongos router on port no 20005 mongo --port 20005 Now type the following commands: use admin db.runCommand({addShard:"10.15.1.208:20000"}) db.runCommand({addShard:"10.15.1.208:20001"}) db.runCommand({addShard:"10.15.1.208:20002"}) Now enable sharding on database “mydb”. db.runCommand( { enablesharding : "mydb" } ) Now provide the sharding key for sharding on collection named “mycoll”. db.runCommand( { shardcollection : "mydb.mycoll", ke...

Security Algorithms (JAVA)

Encryption: It is the process of transforming human readable plaintext to unreadable cipher text. RSA Encryption\Decryption package asymmetric; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.security.Key; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.Security; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import javax.crypto.Cipher; public class RSAText {                 public byte[] encrypt(byte[] input,Key pubKey) throws Exception         ...

Excel Writer (JAVA)

package writer; import java.io.File; import jxl.Workbook; import jxl.format.Alignment; import jxl.format.Colour; import jxl.format.UnderlineStyle; import jxl.write.Label; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; public class ExcelWriter {                 public void writeExcel(String filepath,String values[][]) throws Exception                 {                                 File file = new File(filepath);                          ...