Rituraj tyagi

Greenhorn
+ Follow
since Oct 06, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rituraj tyagi

Hi All

I was trying to save an uploaded file at the location where application(war) is deployed on tomcat server(free hosting plan) by trying getServletContext().getRealPath() but it returned null instead of path but this worked on local machine . Than I tried to save files to local filesystem on server (let us suppose /var/tmp/../file/) but it thrown an exception Permission denied even though the server gets the locations write and read permissions as true . Below is the code:-



I doubt that the problem is with the security policy of the hosting service but not sure . So guys can you please suggest on this.

Thanks in advance

12 years ago
If somebody preparing for Java Platform, Enterprise Edition 6 JavaServer Pages and Servlet Developer Certified Expert Exam then which study materials will be recommended?
Hi All

Putting 2 years will and 15 days of effort I finally got passed SCJP today with 86% not much but still ok . So thanks to javaranch and all its members for helping and guiding me but I'll continue my studies this time for SCWCD and keep posting replies in this SCJP forum at last. Thanks
Hi all

Today I had my OCJP exam but due to some techanical issue it get delayed and I asked the center people to reschedule it to coming monday. Now I got some time with and prep is still fresh but I don't want to waste my time hence please can anybody suggest any site offering free mockup exam for OCJP 6 and also suggestions for the topics which I should keep reviewing now ?

Thanks in advance
Hi All I was going through the K & B again and found in 8 th chapter that this syntax is used to refer by inner class to reference the current instance of the outer class. refer page 669.

Hi Hama

What I got from the reply that var-arg should be taken at least priority and first one should be given to a single object argument which is catch all type. But I guess this is the specific case that sifter(Object o) was preferred first for aa but next time for bb its get exact match with sifter(B[] b).

Thanks Hama got it
Hi All

I been going through exercises in K&B and stumbled upon this code (page 181 question 15)


According to the book the output will be -434 and given argument that arrays are objects but if it is so isn't the output suppose to be -444 (theortically) as the variable ba should be treated as object as variable aa . Please post the link of thread if it is already been asked in this forum.
Thanks in advance
Hi All

I'm also pursuing OCJP and gone through above problem and just extended adithya's example to clear my understanding as follows:-


And got this output :-

Test method invoked in main with innerTest as local from the inner private class
both instance equal

Now what I understand from above this that the line Test test = Test.this got the refrence of the class containing it . Please correct me if I'm wrong.
Thanks

Hi nandini

From best of knowledge there are courses provided by Oracle (Sun previously) related to business functionalities named OCP-BCD (SCBCD previously) Oracle Certified Professional - Business Component Developer and also if you are thinking to pursue this certification than you must hurry cause I came to know (not confirmed) that oracle might add compulsory requirement of some course (definitely charge lot of money) from 1 August 2011.

Good luck
Hello everybody
I m posting the solution myself cause I found it some crooked thing lets get to work straight

SOLUTION-My example I was facing the prob above mentioned now for that I conclude that every midlet needs an permission for using on air connection and in my case I need to get a login response so whenever it asked me for permission till that moment it become the midlet jumps the test condition and show login error so better do one thing I tried is first I put a form saying initializing connection (its a malprcatice I think according to industry standard ) and sending some garbage connection which will be rejected obviously but enable other network connections after that to easily work without any interruption and midlet goes well.

CONCLUSION-At first any midlet trying to using HTTP connection needs that permission first and till the moment it gets it may be too late(due to might be some thread functioning )
so always initialize connection with some useless connection request.
14 years ago
hye Zex
I wont claim big things but I m known to j2me since last 4 months and my self developing a j2me app for sales management which interact between midlet and servlet and
as per my experience if you are using internet GPRS for connecting two devices you may face a gateway access problem. So better to implement fhrough bluetooth wifi etc otherwise you are free to experiment and please if you want some help you can mail me la.89ondevg@gmail.com and as you are novice I think the PDF ebook on "FROM NOVICE TO PROFESSIONAL-APPRESS" cab be best option 4 you (you know google it and download).
14 years ago
PROBLEM-The problem I'm facing is that I'm using a class in a midlet app for network purpose as separate thread (as per newer wtk). But the defect is that the thread doesn't return the data at first time and return second time only I assumed that the main midlet thread may be going too fast so I added join but after that the midlet even stopped working normal and get hangs if anybody wants i can post the source code also here. If have any alternative way please post it. And yes the class is sending a request to a servlet on apache server.

NOTE- If anybody finds the mistakes or any relevant detail missing please notify me

SOURCE CODE (MIDLET THREAD CLASS I M USING )
NETWORK.JAVA

/*
* Network.java
*/



import java.util.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;

/**
* The Network object handles network connections
* to and from the server, the URL is stored in
* the descriptor file.
*/
public class Network extends java.lang.Object implements Runnable
{
private String URL = "http://localhost:8080/MSalesServlet";
private int port = 8080;
private String servlet = "/MSalesServlet";
private Controller controller;
//newely included
private int ch=0;
private StringItem upStatus;
private String tabrod=new String();
private String iden=new String();
private Vector v;
Thread t;


/** Creates new Network */
public Network(Controller controller)
{
this.controller = controller;
if(controller.getAppProperty("MSales-Server-URL") != null) URL = controller.getAppProperty("MSales-Server-URL");
if(controller.getAppProperty("MSales-Server-Port") != null) port = Integer.parseInt(controller.getAppProperty("MSales-Server-Port"));
if(controller.getAppProperty("MSales-Server-Servlet") != null) servlet = controller.getAppProperty("MSales-Server-Servlet");
}

public String getURL()
{
return(URL);
}

public Vector getData(String table, String identity)
{
return(getData(table, identity, null));
}

public Vector getData(String table,String identity,StringItem updateStatus)
{
try{
this.tabrod=table;
this.iden=identity;
this.upStatus=updateStatus;
this.ch=1;
t=new Thread(this);
t.start();
}catch(Exception e){System.out.println("Exceotption e "+e);}
return this.v;
}

public Vector getV()
{
return this.v;
}
public void sendNewOrders(String orders, StringItem updateStatus)
{
this.tabrod=orders;
this.upStatus=updateStatus;
this.ch=2;
t=new Thread(this);
t.start();
}

public void run()
{
try{
if(this.ch==1)
{
this.v=this.getData1(tabrod,iden,upStatus);
this.tabrod="";
this.iden="";
this.upStatus=null;
this.ch=0;
}
else if(this.ch==2)
{
this.sendNewOrders1(tabrod,upStatus);
this.tabrod="";
this.upStatus=null;
this.ch=0;
}
}catch(Exception e){}
}
public Vector getData1(String table, String identity, StringItem updateStatus)
{
Vector items = new Vector();
try
{

HttpConnection hc = null;
InputStream in = null;
OutputStream out = null;
try {
String message1 = "table="+table;
String message2="&id="+identity;
//String url = getAppProperty("PostMIDlet-URL");
//String url = getAppProperty("http:////192.168.1.5:8080//PostServlet");
System.out.println("The url is "+URL);
hc = (HttpConnection)Connector.open(URL);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
hc.setRequestProperty("Content-Length",Integer.toString(message1.length()));
out = hc.openOutputStream();
out.write(message1.getBytes());
hc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
hc.setRequestProperty("Content-Length",Integer.toString(message2.length()));
out.write(message2.getBytes());
in = hc.openInputStream();
//int length = (int)hc.getLength();
//byte[] data = new byte[length];
//in.read(data);
StringBuffer result=new StringBuffer();
int currChar;
while ((currChar = in.read()) != -1)
{
if (currChar != '\n') result.append((char)currChar);
if (currChar == '\n')
{
items.addElement(result.toString());
result = new StringBuffer();
}
}
}
catch (IOException ioe) {
StringItem stringItem = new StringItem(null, ioe.toString());
}
finally {
try {
if (out != null) out.close();
if (in != null) in.close();
if (hc != null) hc.close();
}
catch (IOException ioe) {}
}

/*StringBuffer result = new StringBuffer(); --- old code --------------
if(updateStatus != null) updateStatus.setText("Finding Server...");
HttpConnection c = (HttpConnection)Connector.open(URL+":"+port+servlet+"?table="+table+"&id="+identity);
if(updateStatus != null) updateStatus.setText("Connected...");
InputStreamReader isr = new InputStreamReader(c.openInputStream());
int currChar;
if(updateStatus != null) updateStatus.setText("Transferring...");
while ((currChar = isr.read()) != -1)
{
if (currChar != '\n') result.append((char)currChar);
if (currChar == '\n')
{
items.addElement(result.toString());
result = new StringBuffer();
}
}
isr.close();
c.close();*/
}
catch(Exception e) { System.out.println("Network Exception: "+e.toString()); }
return(items);
}

public void sendNewOrders1(String orders, StringItem updateStatus)
{
HttpConnection c;
OutputStream os;
try
{
StringBuffer result = new StringBuffer();
if(updateStatus != null) updateStatus.setText("Finding Server...");
c = (HttpConnection)Connector.open(URL+":"+port+servlet+"?table=OrderUpload");
if(updateStatus != null) updateStatus.setText("Connected...");
c.setRequestMethod(HttpConnection.POST);
os = c.openOutputStream();
// send request to the servlet
byte msg[] = orders.getBytes();
if(updateStatus != null) updateStatus.setText("Transferring...");
for(int i=0; i<msg.length; i++) {
os.write(msg[i]);
}
// check the response from the server
if (c.getResponseCode() != HttpConnection.HTTP_OK)
System.out.println("HTTP Post Error");
// close all the connections/streams
if(os != null) os.close();
if(c != null) c.close();
}
catch(Exception e)
{
System.out.println("Network Exception: "+e.toString());
e.printStackTrace();
}
}
}

14 years ago