getParameter()==NULL and memory - Java Applet Development

Hi everybody !
I'm creating a web site where users will be able to plot data from a database.
So, I've an HTML code which call a PHP one which himself get data from database and create an JAVA applet on the following model :
echo "<APPLET\n";
...
echo "<PARAM NAME=\"valeur\" VALUE=\"".$string."\">\n";
...
echo "</APPLET>\n";where $string is like "time1%data1#time2%data2#...."
Then I get this string value in the JAVA applet with :
String[] res = getParameter("valeur").split("#");But for too huge data size the getParameter return a NULL value as PHP hadn't create the associated param value.
Does someone have an idea to explain such behaviour ?
Thanks ! 

Not a great idea. PARAM is for shortish strings. If you want to feed huge amounts of data to the applet, have the applet fetch it. 

Thanks for this information concerning the PARAM limitation but now what do you mean by having the applet fetch it ? or more precisely what does it consist in ?
Sorry if it sounds I'm a beginner ! 

Please some help, words, indications concerning the above mentionned "applet fetching".
Thanks a lot ! 

Perhaps ejp had something else in mind, but one approach might be to code the DB query (not the result) in the applet parameter, then have the applet perform the query. 

Exactly, or have it perform an HTTP request of its own to whatever delivers the stuff you are presently putting into the PARAM. 

Many thanks for these responses.
So, now in that case I'll have to execute the query in the applet, and so, on the client side which is not really safe, isn't it ? Since I'll have to export password, etc on the client side ... 

One additionnal question ...
when dealing with <param...> are they consider as POST data from HTML/PHP point of view ?
Thanks. 

nodules wrote:
..in that case I'll have to execute the query in the applet, and so, on the client side which is not really safe, isn't it ?In my suggestion I think the answer is 'yes'.
.. Since I'll have to export password, etc on the client side ...Which is why ejp (who knows far more about remote access to DBs) added..
..or have it perform an HTTP request of its own ..Which I think means to have the applet connect to (for example) a servlet that does the query. The servlet would not expose the password or location of the database, and might do other checks (like that the user is actually allowed to delete every record). ;)

Related

How to make a HTTP Download Mngr that support HTTP server that need userpas

HI, this is the first time i'm in here :D .
as stated in Post title "How to make a HTTP Download Mngr that support HTTP server that need userpas" , i need help as i'm currently so confused with this. i've been using this code in http://www.java-tips.org/java-se-tips/javax.swing/how-to-create-a-download-manager-in-java.html , and added some modification for what i need (simple proxy setting, loading URL text like wget).
i uploaded my Modification, don't worry no viruses it's pure java code ~_~ : http://www.mediafire.com/file/t0yyjckqzm2/TK.zipso i wan't to add the last modification, that is it can access http server that need username and password (sitelogin) like rapidshare premium. but i really don't know how to do this. so if someone capable to teach me how to do this i would be really gratefull
Regards
Richard 
quite possible, but not trivial (especially for someone with very limited experience).
Apache commons has some nice classes to make it easier. 
Hello and welcome to the Sun Java forums.
User/password information in the HTTP protocol is passed as [base64|http://www.source-code.biz/snippets/java/Base64Coder.java.txt] (download source) in the Authorization header, as user:password.
You should pass the user and password in the constructor of Download, alongside the URL (passing it null for both if there is no user/password for the download), then in the run() method you would add
if (user != null && password != null)
  connection.setRequestProperty("Authorization", "Basic " + Base64Coder.encodeString(user + ":" + password));I'll presume you know how to add the fields to the user interface to input that new information.
s
Edit Looce 2008-12-01 13:48:19 GMT: Added "Basic " + to the Authorization line, forgot it before 
Hi Looce, thanks for the greeting :)
yes, i have read some example out there that it need base64encode to passing the username and password. about how to put the userfield interface don't worry i know about it, but what i don't know is to to correctly implemented that base64 encode in my modified code that i post in 1st post. that's what make me so dizzy.
if you could guide me, i would be so thankfull.
Regards
Richard 
Hi jwenting
i've been read some example code that used apache commons too, but too bad i'm one of the very limited experience about this T_T , it's the first time i touch Java.net class 
dewa5227 wrote:
yes, i have read some example out there that it need base64encode to passing the username and password. about how to put the userfield interface don't worry i know about it, but what i don't know is to to correctly implemented that base64 encode in my modified code that i post in 1st post. that's what make me so dizzy.base64 in my earlier post links to a ready-made utility class which encodes (and decodes, actually) to (and from) base64. You can download that class, save it in your project folder and use the methods in it.
s 
any further example implementation/code using about that ? 
dewa5227 wrote:
any further example implementation/code using about that ?Yes, plenty actually. And on the parent page of that source code there are some [samples and documentation|http://www.source-code.biz/snippets/java/2.htm]. In hindsight, I should have pointed you to that parent page first.
s 
hmm --" , more confusing way to implement that in my code --" 
is this link : http://home.tiscali.nl/~bmc88/java/sbook/045.html could be used as reference ? 
Yes, but do not use the BASE64Encoder class from the sun.misc package! sun.misc is not guaranteed to be present on any given machine, and indeed it's not present on mine (using GNU Classpath). Using that class I linked to would be better IMO.
Another thing worthy of mention is that this forum is for advanced programming topics, and you seem to be less able to read through code that I expected. I figured that you would be able to derive from my code snippet how to use the Base64Coder class' encodeString method properly.
s 
Thank You Looce 
You're welcome.
(What about them dukes, though?)
s 
Uh, once question more, did you know a site that have username password authentication available just for testing ? or if you know how to make it, i'll make it in my own host. 
Try the PHP code in Reply #24 of [this thread|http://forums.sun.com/thread.jspa?messageID=10505938#10505938].
s

URL encoding

Hi i am in trouble to understand the implementation of URL rewrting .
i have read tutorial ,posts, but not fluent enough to get the clear picture.
OK , let me tell .
suppose u have a JSP . inside the JSP page u have a form . the form may conatain 2 data .....e.g username,password.....
Now suppose You are sending these 2 data to the server . so your URL will look like as u press submit button
http://localhost:8080/login.jsp?userid=intelchip&password=xxxxx
Q1> so we need to hide it from the user......so we need to encode it which will contain jsessionid ......How ?
[N.B : i   saw a  snippet 
   something like
[code]
URL u = new URL("http://localhost:8080/search");
URLConnection c = u.openConnection();
c.doOutput(true);
DataOutputStream dos = new DataOutputStream(c.getOutputStream());
dos.writeBytes(URLEncoder.encode("username","UTF-8"));
dos.writeBytes("=");
dos.writeBytes(URLEncoder.encode("jana","UTF-8"));
dos.writeBytes("&");
dos.writeBytes(URLEncoder.encode("password","UTF-8"));
dos.writeBytes("=");
dos.writeBytes(URLEncoder.encode("jana","UTF-8"));
dos.writeBytes("&");
dos.writeBytes(URLEncoder.encode("xmldata","UTF-8"));
dos.writeBytes("=");
dos.writeBytes(URLEncoder.encode(yourXMLDataAsaString,"UTF-8"));
dos.close();
c.doInput(true);
InputStream in = c.getInputStream();
Is this Good way ? No, i think there might be smart, compact way to do it so that my url will be encoded . can u tell is there any other way to do it ?
P.S
Note this API
public String HttpServletResponse.encodeURL( String url );
public String HttpServletResponse.encodeRedirectURL( String url ); look it is for the response ...but not for request .......How can encode my data at the request time when i am submitting the form ? the soln i have provided is this smart or unique ? 
In your jsp file you can add an onSubmit attribute on the form that calls a javascript method that calls encodeURI() before actually submitting. 
javascript method that calls encodeURI()
do u want to use encodeURI() from javascript 1.5 ? wii it give jsessionid in the url ?
i saw a site when you press submit button the url looks
......abcd.do?jessionid=cccccsssdewdewd123#777
something like this . NOTE we are doing request to the server
I wish to know how they did it ? 
why r u using get method in the form? Use post method... 
why r u using get method in the form? Use post
method...Any particular reason for advocating POST?
http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist 
Url encoding consists of removing certain characters like space, punctuation etc
and replacing with escape characters.
for eg if the url you mentioned in your post was
http://localhost:8080/login.jsp?userid=intel chip&password=xxx xx (notice the white space in the name and pwd)
the effect of rewriting it would be
http://localhost:8080/login.jsp?userid=intel%20chip&password=xxx%20xx (note the white spaces have been replaced by escape sequences)
The browser automatically encodes url before sending the request across to the server.
if u manually want to do it, consider using java.net.URLEncoder.encode()
url rewriting is the process of appending the url with a query string, usually a session id for browsers that dont support cookies or where cookies have been disabled. (by default session ids are stored in cookies)
the encodeURL() in the servlet api does url rewriting (misleading... ?)
url rewriting is a server side process. for eg you may want to send a html page from the servlet.The html page may have an url which you should rewrite (for session management), hence it is natural to expect that this would be a method of the response object.
none of this however has any effect of hiding data from the user (i think you got confused by the term 'encode').
if you wish that the username and pwd dont appear in the url, use a post method.
ram. 
Hai annie,
Thanx for the useful link.
I suggested POST method becaz it's doesn't reveal the username and password in URI. Thus it can't be bookmarked by anyone. 
To
Madathil_Prasad
I just want to say, I learnt many things from your post ........... this post is an asset to me. Thanks for that excellent answer. yea, i confused with the name "encode"which u have pointed out..... its OK now.
Thank u very much. 
Any particular reason for advocating POST?
http://www.w3.org/2001/tag/doc/whenToUseGet.html#check
listI just had a look at that article's introductory summary. I noticed that it fails to mention the amount of data transferred with a request. Since IIRC GET parameters usually will be saved as environment variables (as opposed to a stream with POST) in CGI, it might not be suitable for very long values like text area input, due to OS restrictions. Also, uploading a file using GET makes no sense, and the aforementioned "parameter hiding" is a valid consideration, too, IMHO. 
Since IIRC GET parameters usually will be saved as environment
variables (as opposed to a stream with POST) in Not sure what you mean here, the response of a GET will typically be saved by the browser or proxy server in "HTTP_REFER" field, but other than that I don't know what you mean....
it might not be suitable for very long values like text area input, due to OS
restrictions.the HTTP RFC specifies a limit for GET queries, IIRC. Something like 5012. 
I dont think URLEncoder.encode() od java.net gives the same output as encodeURI() method jscript

How can I compact a MSAccess database with java?

Hi. I have a question (Please Help!!!): How can I compact a MSAccess database with java-jdbc? Is it posible? Thanks
no.
what sql call are you proposing to make?
that's one of the reasons why access can be problematic.
% 
Please refer
http://www.javaworld.com/javaworld/javaqa/2000-09/03-qa-0922-access.html 
dvohra09,
your reference is about how to "connect" to Access...
The question was about how you "compact" an Access database, i.e. tell Access (or the Jet Engine) to remove unused space and produce a smaller DB file. Doing that improves performance of Access, in some cases dramatically.
If there is any way to do so from the JDBC world, it would be via Access (or Jet Engine)-specific stored procedures, that either do it directly, or allow you to invoke Access objects such as the one mentioned here:
http://www.mvps.org/access/general/gen0041.htm
I have no idea if Access has anything like that. 
You cannot do this (compact Access databases through JDBC). You can programmatically do it with ADO but that is not ODBC.
So you are out of luck on the JDBC front. There may be some way of doing it from a process but this seems rather involved although it would be possible. Just difficult. Best way to solve it would be to have the user do it once in a while directly. Normally though unless you have alot of forms you aren't going to have much reason to compact.
Have a happy day. 
MS Access database has a max length limitation of 2.14GB for Access 2000( 1.07G for Access 97), and won't recycle basically space for update/delete sql so tha it's a good idea to use MS Access database for program, which need update/delete frequent ly data. The programmers of HXTT Access(www.hxtt.net) are writing code for CREATE TABLE/DATABASE sql now. If you need a pure Java solution for PACK TABLE/DATABSE urgently in your project, you should send such a requirement to the Support page of www.hxtt.net so that they can schedule complementing such a fucntion. Otherwise, you should pack your databae manually or visit C++ code for Compact an Access Database Programmatically at
http://www.codeguru.com/Cpp/data/mfc_database/microsoftaccess/article.php/c4327/ , or use Easy Microsoft Access MDB MDE Compactor at http://www.easyhr.com.au/software/easy_mdb_mde_compactor.htm. 
hi,
I am looking for this "solution" also. But I do have a work around....
which I call a VB program that has code to compact a MS Access, passing in as a param.
good luck 
I would like to use the program to compact the db access. If you have the .exe file I could call it by the java API exec().
Would you mind to email me the program utility you use?
diegosacc73#hotmail.com
Thanks. 
threads that are a year old aren't often answered in this way.
and how stoopid do you have to be to post your email in a forum like this?
% 
Ehy .. idiota, why don't you waste your time to give me actually an helpful response? 
Ehy .. idiota, why don't you waste your time to give
me actually an helpful response?You get what you get here, eejit.
I don't know how to do it because I use relational databases that don't require compaction. I wouldn't deploy any serious app using Access. It's a desktop database intended for a single user, not an enterprise application.
% 
Use the following code .. First Make MSACCESS.EXE global by setting up path variable
public class Temp
{
public static void main(String[] args)
{
try
{
Runtime.getRuntime().exec("rundll32 SHELL32.DLL , ShellExec_RunDLL MSACCESS c:\\mydb.mdb /compact");
}
catch(java.io.IOException e)
{
System.out.println("Compaction failed :"+e);
}
}
} 
The problem is :
java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDataSource
It runs inside normal applet call. But it doesn't run within html.
<APPLET CODE="SampleApplet_2.class" WIDTH=500 HEIGHT=500>
<PARAM NAME=TEXT VALUE="Hi There">
<P>Hi There<P>
</APPLET> 
Please leave old threads for dead. 
senem wrote:
The problem is :
java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDataSource
It runs inside normal applet call. But it doesn't run within html.That question has absolutely nothing to do with this thread.
Nor is it likely to even have anything to do with MS Access (since that driver is for SQL Server).

Prevent from replacing double slashes with one in url

Hello every body,
I'm trying to send a post request to some url, but that url has double slashes (other than http://) in the middle, like
http://someDomain.labla.com//somethingWithParameters
server refuses my request. the reason is that java turns this url into
http://someDomain.labla.com/somethingWithParameters
some where in java, every double slashed url validates and turns into oneslashed.
How can i prevent this ? 
http://someDomain.labla.com//somethingWithParameters
server refuses my request. the reason is that java turns this url into
http://someDomain.labla.com/somethingWithParametersWhy shouldn't it? What's the difference? 
In my case, server provides me a hash and this url.
after normalization, the url won't match the hash, so server denies my request,
And I can't hash it myself, cause I don't have server hash algorithm. 
As far as I now, Uri has a normalize method, which is called during apache HttpClient.execute, and thats the problem. 
I con't remember where to look but I thought a double slash anywhere in a URI other than after the protocol name was illegal. If I am right then the person supplying the URL needs to correct it. 
Yes, he needs but he wont,
He's using an old framework and refuses to change it, 
Fahim wrote:
As far as I now, Uri has a normalize method, which is called during apache HttpClient.execute, and thats the problem.Not in my view. I would expect the URI to be normalised prior to the hash being made. 
thats the problem.What problem? There is no problem in evidence here. Just someone who doesn't understand the rules of URLs. 
Fahim wrote:
Yes, he needs but he wont,
He's using an old framework and refuses to change it,Then you seem to be stuffed. 
I need to get this application to working,
and the site owner doesn't want to spend money.
EJP wrote:
thats the problem.What problem? There is no problem in evidence here. Just someone who doesn't understand the rules of URLs.The fact that he does not understand the rules, won't make my application working, neither your persistence of denying the existence of problems!!! 
Fahim wrote:
neither your persistence of denying the existence of problems!!!We are not denying the existence of problems! I think a technical solution from your end is probably impossible. I can't be sure since I can't see any of the code you are working with but ... 
thanx for your time.
HttpPost post = new HttpPost(loginUrl);
post.setEntity(new UrlEncodedFormEntity(params, HTTP.DEFAULT_CONTENT_CHARSET));
HttpClient client = getClient() ;
HttpResponse resp = client.execute(request);where params is a list of params and getClient() get the client which has the right cookies. 
Maybe modify the Apache code? 
Meet him.
This document, by Tim Berners-Lee, estabilishes the syntax of Uniform Resource Locators.
http://www.w3.org/Addressing/URL/url-spec.txt
Show your boss the BNF definition of a "httpaddress" (scroll to page 13).
Then show him that neither a "path" nor a "segment" (as defined by that grammar) may contain two consecutive slashes.
Finally, kindly tell him he's using a broken framework that violates the specification. 
thanx both.

how to set up connection between S and C

I want to realize a chat between server and client.
on both side ,there is a textArea to get the information to send to the other.
I know the socket is must be used,but how to set up the data source(from textarea or textfield),and how to store the data?
can some one tell me how to do this?
thanq! 
I'm really not sure what your implementation is but maybe you need to use URL's.
http://www.(path to computer)/username/(path to file)/file 
sorry, I think I misunderstood your question. you need to use something like aglets or servlets. By using these things you can emcapsulate all meesage information and pass these messages between the server and client 
lol. I'm a little slow tonight!
Try using ACL (Communication Language) with aglets(not sure how to deal with servlets) you can set arguments.
eg
setArgs(":name", "me")
then after the object has received a message;
message.getArgs(":name")
Please don't use the above code cause it is pseudocode.
Hope this helps 
plz,dont make things complex.
i think this need not the .... you have said.
I think socket and IO is enough.
thanq!~~ 
I think you are right. I was thinking about a different implementation and unfortunately I don't know much about sockets. 
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html 
dunedinhigh,the page really give me some help.
but here the information to send between sever and client is got from console,what I mean is just how to got information from TEXTAREA. 
what I mean is just how to
got information from TEXTAREA.You use its getText() method. 
So what are you saying you dont know how to use the textarea and textfield?Cause it is ez to convert that code that dunedinhigh gave you from console to a gui like what you want I think.So here is a link that shows you how to use text component.You learn this then you can put 2 and 2 together.Also check out the java tut page.
http://java.sun.com/docs/books/tutorial/
http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html
good luck 
no ,no .I know how to use textarea,how to get text from it.
maybe my description is not clear.:-)
to describe more simple way:put the "text in the textarea" in the XXXstream,then I can use stream to send them.
OK this is what you do you have a socket,stream ,textfield/textfield
you open the socket then you use your streamwriter to write to that socket and the string you are going to write is the string that comes from the textfield/textarea
so String text = textsomething.getText(); and to read the data in you can use the setText() the same way.Good luck 
(Server):text(from textArea)-->XXXstream-->socket
-->client
ok?what make me complex is the first arrow

Categories

Resources