You Are Here:

Community: Developer Discussion Boards

#1 Old J2ME - use an external directory from a .jar - 2008-06-27, 01:32

Join Date: Jun 2008
Posts: 3
catalin.manea
Offline
Registered User
Hello,

I am working at a Web Server for Mobile Devices in J2ME. I made allready the base structure with sockets. My only problem for now remains the HTTPDOCS directory where I need to put the xhtml, css, imagines, servlets and over files which it can be acces from a browser on the Internet or localhost. I create a path to this directory in SRC (I use netbeans) and it works (with little problems but is a step foward). The problem is if I do this I need to include the HTTPDOCS directory into the .JAR and if I do that I can't change the files from the public directory unless I build the application again.
I presume that I need to work with an external directory or external resources but I don't have any ideea how to do that.

Please help me.
Reply With Quote

#2 Old Re: J2ME - use an external directory from a .jar - 2008-06-27, 08:29

Join Date: Nov 2003
Posts: 3,641
Location: Bangalore , India
Send a message via Yahoo to balagopalks
balagopalks's Avatar
balagopalks
Offline
Forum Nokia Expert
Hi catalin.manea! Welcome to Nokia Developer Discussion Boards!! :)

Have a look at JSR 75 File Connection API. May be it could help to satisfy your requirements.

MIDP: FileConnection API Developer's Guide (with Example) v2.0

Regards
Gopal
Reply With Quote

#3 Old Thumbs up Re: J2ME - use an external directory from a .jar - 2008-06-27, 15:45

Join Date: Jun 2008
Posts: 3
catalin.manea
Offline
Registered User
Thank you balagopalks! I think this is what I need. I hope I can change and understand the dir's path, because in this moment I have something like this:


Code:
String request;

// Allows to access the webserver content like resources
Class resource = this.getClass();

......................................................
// READ THE BUFFER and if is not empty do this:

request = new String(buffer,0,length);

// Obtaing the resource path specified by the get request
String path = request.substring(4,request.indexOf("HTTP") - 1);

// if is a directory sends the index.html
if(path.endsWith("/"))
   path += "index.html";

// Adds the request path to the path specified
   path = "/httpdocs" + path;
                                        
// Open the request path with the help of resource as Stream
InputStream reader = resource.getResourceAsStream(path);

// If the reader is null, the request is not found, sends a error 
if(reader == null)
  // stop here because the httpdocs directory was't found :(
else
{
  // the httpdocs dir was found so read the buffer, etc. 
}

I think instead of that peace of code I need to do something like dir = (FileConnection)Connector.open("file://localhost/" + currDirName); but I don't understand where to get this file on localhost and how to get the resource as a stream for this path.

Someone have an ideea ?
Reply With Quote

#4 Old Re: J2ME - use an external directory from a .jar - 2008-06-28, 23:53

Join Date: Jun 2008
Posts: 3
catalin.manea
Offline
Registered User
Nobody knows? :(
Reply With Quote

#5 Old Re: J2ME - use an external directory from a .jar - 2008-06-30, 14:12

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
Hi catalin.manea,

your considerations are right: in your code, you'll need to change the getResourceAsStream() part with related FileConnection methods. Once you get a FileConnection, you can get the InputStream of the related file with the openInputStream() method. So, your code, apart from this, would not need alot of changes.

About the file paths, it depends a lot on how and which file you want to be read and published by your HTTP server. Anyway, checking the link posted by Gopal would help you a lot in finding more useful answers.

Pit


www.jappit.com - mobile and web blog
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Ayuda con j2me polish robervelez Foro en Español (Spanish Forum) 2 2007-06-06 21:44
IS IT POSSIBLE IN J2ME APPLICATIONS TO TAKE DATA FROM EXTERNAL SOURCES? shruthirs Mobile Java General 2 2007-04-09 19:47
How can the WAP browser communicate to J2ME application? hbfornies Mobile Java General 20 2007-03-02 17:32
External debugger with Nokia J2ME Emulator -- HOWTO maffeis Mobile Java Tools & SDKs 0 2003-09-12 16:16
how to avoid linking error skdas General Symbian C++ 6 2003-07-07 08:57

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia