Welcome to my blog, hope you enjoy reading
RSS

Saturday, 17 November 2012

Gwt Json


Gwt Json

Step1: Create the GWT project

Step2: Create the Servlet in server package
example:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class JsonStockData extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try
{
PrintWriter out = resp.getWriter();
out.println('[');==================//Start of the json data
String name = req.getParameter("q");
String encryption=byteArrayToHexString(computeHash(name));
out.println(" {");===============//Start of the object
out.print(" \"name\": \"");=========//key for pojoclass variable
out.print(name+"\");=================//value for pojoclass variable
out.println(",");===================//separetion for the variables
out.print(" \"encryption\": \"");
out.print(encryption+"\"");
out.println(" },");===============//end of the object
out.println(']');==================//end of the json data
out.flush();
}catch(Exception e)
{
System.out.println(e);
}
}
public byte[] computeHash(String x) throws Exception
{
java.security.MessageDigest d =null;
d = java.security.MessageDigest.getInstance("SHA-1");
d.reset(); d.update(x.getBytes());
return d.digest();
}
public String byteArrayToHexString(byte[] b)
{
StringBuffer sb = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++)
{
int v = b[i] & 0xff;
if (v < 16)
{
sb.append('0');
}
sb.append(Integer.toHexString(v));
}
return sb.toString().toUpperCase();
}
}
Step 3: Add the following data in web.xml
example:
<servlet>
<servlet-name>jsonStockData</servlet-name>
<servlet-class>com.json.server.JsonStockData</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jsonStockData</servlet-name>
<url-pattern>/jsonproject/jsonproj</url-pattern>
</servlet-mapping>

Step4: Write the jsonobject class in client package

example:
import com.google.gwt.core.client.JavaScriptObject;

public class jsondata extends JavaScriptObject
{
protected jsondata(){}
// JSNI methods to get stock data.
public final native String getName() ======//javaobject see servlet(step2)
/*-{ return this.name; }-*/;
public final native String getEncryption()
/*-{ return this.encryption; }-*/;
}

Step 5: Call the url in the client side
Step 5.1: formate the url
example:
private static final String JSON_URL = GWT.getModuleBaseURL() + "jsonproj?q=";

Step 5.2:Add the query Strings
example:
String url = JSON_URL+”name”;
url = URL.encode(url);


Step 5.3:Send request to the server
example:
// Send request to server and catch any errors.
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
Request request = builder.sendRequest(null, new RequestCallback()
{
public void onError(Request request, Throwable exception)
{
Window.alert("Couldn't retrieve JSON");
}
public void onResponseReceived(Request request, Response response)
{
if (200 == response.getStatusCode())
{
Window.alert(response.getText());
updateTable(asArrayOfJsonData(response.getText()));
}
else {
Window.alert("Couldn't retrieve JSON2 (" + response.getStatusText()
+ ")");
}
}
});
} catch (RequestException e) {
Window.alert("Couldn't retrieve JSON1");
}

Internal methods for the above code:
==========This method for the getting and divide the json objects=====
private void updateTable(JsArray<jsondata> jsArray)
{
for (int i = 0; i < jsArray.length(); i++) {
updateTable(jsArray.get(i));
}
}
==========This method for getting the each object and values=====
private void updateTable(jsondata jsondata)
{
Window.alert(jsondata.getName()));
Window.alert(jsondata.getEncryption()));
}

==========Convert the string of JSON into JavaScript object=====
private final native JsArray<jsondata> asArrayOfJsonData(String json)
/*-{
return eval(json);
}-*/;
Share

Thursday, 15 November 2012

taglib definition not consistent with specification version


Problem:
             The application is developed in the tomcat6 version and now it is using in tomcat7 then the error is

org.apache.catalina.startup.ContextConfig parseWebXml
SEVERE: Parse error in application web.xml file at jndi:/localhost/Rsystem/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/Rsystem/WEB-INF/web.xml; lineNumber: 40; columnNumber: 11; Error at (40, 11) : taglib definition not consistent with specification version
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2719)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1279)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1340)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)
at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1825)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1201)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.IllegalArgumentException: taglib definition not consistent with specification version
at org.apache.catalina.startup.TaglibLocationRule.begin(WebRuleSet.java:1240)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)
... 30 more


Solution:


Step1:   In web.xml write the following code.
<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    version="3.0">
Step2:   Write all the <taglib> in following

<jsp-config>
  <taglib>
  </taglib>
  <taglib>
  </taglib>
</jsp-config>
Step3: Download jstl-1.2.jar and drop it in /WEB-INF/lib.
Step4: Restart the tomcat.
Share

Struts Plugin for Eclipse


Step 1: Go to Eclipse and from menu select Help->Install New Software.

Step 2Add the following update site using 'Add' button

             http://download.jboss.org/jbosstools/updates/stable/indigo/ (for eclipse indigo)
                                      or
             http://download.jboss.org/jbosstools/updates/stable/helios/ (for eclipse helios)

Step 3: in eclipse select  File-->new-->Others-->JBoss Tools Web-->Struts-->StrutsProject.


Share

Unbound JRE after importing a project from a different operating system



Problem: The JRE set for the Embedded Transaction project shows as unbound after you import an Embedded Transaction project on Windows® XP that was exported from a Linux® environment.
Solution: Complete the steps below to manually remove the JRE and add it again.
  1. Right-click the project, and then select Properties > Java Build Path.
  2. From the Libraries tab, select the Unbound JRE, and then press Remove.
  3. Click Add Library, select JRE System Library, and then click Next.
  4. Select Workspace default JRE (jclDesktop Win32 x86), and then click Finish.
Share

Friday, 9 November 2012

Ubuntu commands



for giving permisions


>chmod -R 777 filename/foldername

for know the processes of any application

>ps aux|grep eclipse             for eclipse

for kill the processes

>kill -9 processnumber

For see the tomcat log changes in console

>tail -f catalina.out

recursively delete some folder in subfolders also


Try to recursively delete all .svn folders from your project's root folder. For example, on a Linux machine, you should issue the following command in the project's root folder:

rm -rf `find . -type d -name .svn`

INSTALL Tomcat7
 
sudo apt-get install tomcat7

How to download file in ubuntu using terminal

Open terminal and type

  • wget "http://domain.com/directory/4?action=AttachFile&do=view&target=file.tgz" 

to download the file to the current directory.

  • wget  -O /home/omio/Desktop/ "http://thecanadiantestbox.x10.mx/CC.zip"


will download the file to /home/omio/Desktop

Share

Date time picker in html






Description: Date Time Picker allows your visitors to easily input a date/time into a form field, by selecting it from a popup window. Supports output dates in various formats such as: dd/MM/yyyy, dd/MMM/yyyy, MM/dd/yyyy etc. An extremely versatile script.
Example:
1) Date (MM-dd-yyyy) Pick a date
HTML code: <input id="demo1" type="text" size="25"><a href="javascript:NewCal('demo1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
2) Date & Time(12-Hour) (dd-MMM-yyyy hh:mm:ss) Pick a date
HTML code: <input id="demo2" type="text" size="25"><a href="javascript:NewCal('demo2','ddmmmyyyy',true,12)"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
3) Date & Time(24-Hour) (dd-MM-yyyy HH:mm:ss) Pick a date
HTML code: <input id="demo3" type="text" size="25"><a href="javascript:NewCal('demo3','ddmmmyyyy',true,24)"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
Directions
1. Download the following zip file, which contains the necessary files plus a demo. 2. Upload "DateTimePicker.js" and "cal.gif" contained within the above zip file to your web site.
3. In the <head> section of your webpage that will display the Date Picker, insert the below code:
<script language="javascript" type="text/javascript" src="datetimepicker.js">

//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com

</script>
4. Create the desired textboxes that will use the Date Time Picker. A sample textbox looks like:
<input id="demo1" type="text" size="25"><a href="javascript:NewCal('demo1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
As seen above, enter a unique ID into each <input> tag (in this case, "demo1"), and inside function "NewCal()", pass this ID as its first parameter. Below describes NewCal() in detail:
NewCal([textbox id],[date format],[show time in calendar?],[time mode (12,24)?]) a. You must enclose textbox id and date format with single quotes (').
b. Don't insert date separator in between of date format such as dd-MM-yyyy.
c. Parameters for "NewCal" function:
  • Textbox id (Mandatory)
  • Date format (optional) - If you don't specify date format, the default date format will be "dd-MM-yyyy". Other valid date formats for My Date Time Picker are: ddMMyyyy,MMddyyyy,ddMMMyyyy,MMMddyyyy.
  • Show time in calendar? (optional) [true or false] - Specify "true" if you would like to let user to pick a time. Default value is "false".
  • Time Mode (optional) [12 or 24] - Time shown in 12-hour or 24-hour format. Default is 24-hour format.
Customization If you have little bit of javascript and html knowledge. You will be able to customize the calendar look by yourself.
The first step is to open DateTimePicker.js file itself and you'll find "configurable parameters" section at the header.
//Configurable parameters
var cnTop="200";//top coordinate of calendar window.
var cnLeft="500";//left coordinate of calendar window.
var WindowTitle ="DateTime Picker";//Date Time Picker title.
var WeekChar=2;//number of characters shown for week day. if 2 then Mo,Tu,We. if 3 then Mon,Tue,Wed.
var CellWidth=20;//Width of day cell.
var DateSeparator="-";//Date Separator, you can change it to "/" if you want.
var TimeMode=24;//default TimeMode value. 12 or 24

var ShowLongMonth=true;//Show long month name in Calendar header. example: "January".
var ShowMonthYear=true;//Show Month and Year in Calendar header.
var MonthYearColor="#cc0033";//Font Color of Month and Year in Calendar header.
var WeekHeadColor="#0099CC";//Background Color in Week header.
var SundayColor="#6699FF";//Background color of Sunday.
var SaturdayColor="#CCCCFF";//Background color of Saturday.
var WeekDayColor="white";//Background color of weekdays.
var FontColor="blue";//color of font in Calendar day cell.
var TodayColor="#FFFF33";//Background color of today.
var SelDateColor="#FFFF99";//Backgrond color of selected date in textbox.
var YrSelColor="#cc0033";//color of font of Year selector.
var ThemeBg="";//Background image of Calendar window.
//end Configurable parameters

Share

Copy data of One Database Table to Another database table

Copy data of One Database Table to Another database table

INSERT INTO destinationdatabase.destinationtablename SELECT * FROM sourcedatabase.sourcetablename

Share

Update multiple rows with multiple values and multiple conditions mysql

Update multiple rows with multiple values and multiple conditions mysql

I am facing a complex situation of SQL queries. The task is to update multiple rows, with multiple values and multiple conditions. Following is the data which I want to update; Field to update: 'sales', condition fields: 'campid' and 'date':
if campid = 259 and date = 22/6/2011 then set sales = $200
else if campid = 259 and date = 21/6/2011 then set sales = $210
else if campid = 260 and date = 22/6/2011 then set sales = $140
else if campid = 260 and date = 21/6/2011 then set sales = $150
Share

How do I delete from multiple tables using INNER JOIN IN SQL

How do I delete from multiple tables using INNER JOIN IN SQL

DELETE t1,t2,t3 
FROM Filedata AS t1 
INNER JOIN Filepath as t2 
INNER JOIN Fileversions as t3 where t3.file_id='0.9067535276368446'

Share

one column in onetable is insert into another table in mysql query

one column in onetable is insert into another table in mysql query

 
update Fileversions
set    Fileversions.filename = (select Filedata.filename
                  from Filedata 
                  where Fileversions.file_id=Filedata.file_id)
where exists (select 1
              from Filedata
              where Fileversions.file_id=Filedata.file_id) 
 

for more quries

Share