i am using GWT
I trying to dowload a file using Servlet.
I have fileId on the client side.
i have my servlet ready to look for the file using fileId and send back to client.
But on the Client side.
I dont understand how to send this id and retrieve this on server side to use it.
String fileId = "aValidId"
Window.open(GWT.getHostPageBaseURL() + "DownloadFileServlet", "", "");
Can any one help me to do this.
If this question is repeated , please send me a link (i could not find it )
Thanks in advance
You can simply append the parameter to the servlet path like below
String fileId = "aValidId"
Window.open(GWT.getHostPageBaseURL() +
"DownloadFileServlet?fileId ="+fileId , "", "");
And in servlet get the parameter like below:
String myParam = req.getParameter("myparam");
And please go through the below link for encoding and for other techniques..
http://perishablepress.com/how-to-write-valid-url-query-string-parameters/
Related
I want to open a file stored on server on click of a button on client side.
On click handler I added code-
String url="../../downloadServlet?fileName="+fileN+"?recodId="+recoId;
Window.open(url, "", "");
In this url , I want to add 2 diffrent parameters- FileName and RecordId.
Above implementation is not working for this. How can i pass more parameters in a request?
Thanks
try to use & instead of another ?:
String url="../../downloadServlet?fileName="+fileN+"&recodId="+recoId;
I am trying to send a dynamic link via email with the following code.
Message messageSSL = new MimeMessage(session);
int hash=1000;
String content="click here";
messageSSL.setContent(content, "text/html");
However, i have failed to generate a dynamic link.The output in the mail is in the plain text format.
Output (In the mail):
click here
Even though, the following code works and generates a link called "click here".
String content="click here";
Thanks!!
I think the problem is with backward slash. We should be using forward slash in urls. Please change and try it.
The Apache Commons Email library has some useful classes that take care of the low-level details for stuff like making HTML email work properly. Check it out:
http://commons.apache.org/proper/commons-email/
can you please enclose the link by html tag and try once.
String content="<html><body>click here </body></html>";
i am using same library and working fine for me.
please check below thread
How Can I put a HTML link Inside an email body?
I have developed a file download program, which is implemented by Java Servlet.
The link sent to the user is in the following format:
http://examples.com/file?id=6565_1_1_1_201110
When user clicks this link, it will send a request to a servlet program to find the file name and then download the file. In the servlet I use the following code to retrieve the id value:
String param = "";
synchronized (this) {
param = request.getParameter("id");
}
Now the problem is, some users can get the correct value, which is 6565_1_1_1_201110. However, some users have obtained the wrong value, like 656543_1_1_1_20111067, etc, which is not fixed. I do not know where are those additional number from?
Any idea on this? Thanks.
First, sorry for my english it's not my native language.
So, I am working on an application in JSP and in one of my forms I have a field "comments". When I submit this form, the value of this field is sent to my servlet by an ajax request.
var request = 'mainServlet?command=SendRequest';
request += ('&comments=' + $('#comments').val());
But when there is a "<" or ">" in the field, $('#comments').val() translate them into "<" or "&gl". For exemple, is converted to < ;test&gl ;
And when I want to recover the value in my servlet, I do:
String comments = request.getParameter("comments");
But the url looks like : mainServlet?command=SendRequest&comments=< ;test&gl ;
So request.getParameter("comments"); returns an empty string.
I thought that I could replace the string like < by my own code and then replace it again in my servlet, but is there a simpler way to do this?
Thanks.
Edit: After, I reuse the comments in an other jsp.
I believe what you need is the encodeURIComponent function. It will convert any string into a format that you can use inside a URI.
Just remember to decode it on the receiving end, I believe the URLDecoder class can do this for you.
I'm trying to make use of google api as text-to-speech. So, I build a String then should pass it as a URL to a component to obtain a MP3 with the spoken words.
So, this is my code:
URI uri = new URI("http://translate.google.com/translate_tts?tl=es&q="+ URLEncoder.encode((String)this.text.getValue(), "UTF-8"));
When I make uri.toString() its return a well formed URL. If I copy and paste this output in the browser works pefectly.
But if I assign this returned String to the source property of a ice:outputMedia is not working. Then inspect the HTML generated in the page and the String in src property is:
http://translate.google.com/translate_tts?tl=es&q=Bobby+need+peanuts
The & symbol has been replaced by &.
How can I avoid this to make a valid URL?
You need to decode the url on the client side using Javascript.
var decoded = decodeURI(URI)