Wednesday, 16 April 2014

Run Batch File As Administrator Mode in Windows

Here i am going to share my problem and solution.I write a batch file but it run only in administrator privilage. So i tried to run batch file in admin mode.Here the solution is,

Fist create batch file using below code,In blue lines i create a batch command for restart Apache Tomcat.If you need change the code as per your requirement.


:: Automatically check & get admin rights
@echo off
ECHO =============================
ECHO Running Admin shell
ECHO =============================

if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 5 >> "%temp%\OEgetPrivileges.vbs"
exit /B

setlocal & pushd .

REM Run shell as admin (example) - put here code as you like
sc stop Tomcat7
ping -n 1 -w 3000 > nul
sc start Tomcat7
cmd /k exit


I hope this will work for you..Thanks for reading this .

Monday, 31 March 2014

Redirect JSP or HTML page Using Javascript

The code for redirect html or jsp page using javascript fuction.

1)Copy below the code and save as filename.html or jsp.
2)Then create login.jsp page.
3)After that run the page filename.html and click the button it will navigate to login.jsp page.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function myfunction(){


<form name="form1" action="">
<input type="button" name="button1" value="click" onclick="myfunction()"/>



Sunday, 9 March 2014

Apache Tomcat Problem in Eclipse

Hey guys,today i am going to share my problem in eclipse and the solution for the problem. I deleted the tomcat 7 server in my eclipse after that i cant able to add new server in the name of tomcat 7. So i googled it and searched in near 1 hour and finally find the solution. The Steps to solve this problem, 1)Close your eclipse Application. 2)Go to your workspace-directory-->.metadata-->.plugins-->org.eclipse.core.runtime-->.settings folder. 3)Now we are going to delete two files in this folder. 1)org.eclipse.jst.server.tomcat.core.prefs 2)org.eclipse.wst.server.core.prefs 4)Now close the window and now open your Eclipse Application. 5)Find Server Tab then right click new-->Server-->Select Apache Tomcat 7 and browse the Tomcat 7 installed location then click Finish. Now i hope your server is running...

Tuesday, 25 February 2014

String Multi Character Split in Java

Hi friends,

We already know the basic String split function using java. Now this post describe to split String which contain multi-character and we are going to split in single array.


public class stringSplit {
public static void main(String args[]){
String str="a+b-c*d";
String strarray[]=str.split("[\\+\\-\\*\\/]");
for(int j=0;j<strarray.length;j++){




Similar Posts:

Tuesday, 31 December 2013

Run java Program Every One Hour

This post describe the automation of java program run continuously using timer class. Here i coded this program run every one hour(1000 * 60 * 60 ).If you need change the time interval change your timing instead of 60.If you need to run the program only in particular day use


import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class EveryHour extends TimerTask {

  public void run() {
 Calendar date = Calendar.getInstance();
 int n=date.getTime().getMinutes();
    System.out.println("Generating report:"+n+":"+date.getTime());
    //TODO generate report

  public static void main(String[] args) {
    Timer timer = new Timer();
    Calendar date = Calendar.getInstance();
//    date.set(
//      Calendar.DAY_OF_WEEK,
//      Calendar.TUESDAY
//    );
    date.set(Calendar.HOUR, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    // Schedule to run every Sunday in midnight
      new EveryHour(),
      1000 * 60 * 60


I hope it will help you.Thanks for visiting this page.

Open Webpage URL in Java Swing Application

Hi guys,here i am posting the method ,how to view webpage in swing application.

import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class url {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        Browser browser = new Browser(shell, SWT.NONE);
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())

Here we also use the static html file open using,

Wednesday, 6 November 2013

Read XML File using Java

This post describes about ,how to read data from xml file using java.


import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

public class readXML {

  public static void main(String argv[]) {

    try {

File fXmlFile = new File("d://file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);


System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

NodeList nList = doc.getElementsByTagName("Value");

System.out.println("node length:"+nList.getLength());
for (int temp = 0; temp < nList.getLength(); temp++) {

Node nNode = nList.item(temp);

System.out.println("\nCurrent Element :" + nNode.getNodeName());

if (nNode.getNodeType() == Node.ELEMENT_NODE) {

Element eElement = (Element) nNode;

System.out.println("Value id : " + eElement.getAttribute("id"));
System.out.println("tag1 : " + eElement.getElementsByTagName("tag1").item(0).getTextContent());

System.out.println("tag2 : " + eElement.getElementsByTagName("tag2").item(0).getTextContent());

    } catch (Exception e) {



Root element :Root
node length:5

Current Element :Value
Value id : 1111
tag1 : check1
tag2 : 2

Current Element :Value
Value id : 1122
tag1 : check2
tag2 : 12

Current Element :Value
Value id : 1133
tag1 : check3
tag2 : 22

Current Element :Value
Value id : 1441
tag1 : check4
tag2 : 32

Current Element :Value
Value id : 1155
tag1 : check5
tag2 : 42


Similar Posts:

Create XML file in Java using Loop