You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Yury Luneff <bi...@ya.ru> on 2009/02/27 09:00:34 UTC
doing post request to a tapestry page
Hello, users.
I'm trying to link a java applet to jetty/tapestry. I need to
pass data through POST request. I'm doing it like this:
URL url = new URL("http://localhost:8080/FileReceiver");
System.out.println(url.toString());
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(false);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded; charset=utf-8");
PrintWriter pw = new PrintWriter(connection.getOutputStream());
and then filling the Pw. I'm not interested in input from
FileReceiver, so there is a "false" for that.
On the tapestry side i thought it would be possible to handle
this request somehow defining an event for FileReceiver, such
as onActivate or FileReceiver:receive onReceive. It reacts on
browser request, but not mine.
What is the right way of doing this (passing large data by
POST&java to tapestry application)? commons.httpclient is 50
times bigger than applet itself :)
--
Best regards,
Yury
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re[3]: doing post request to a tapestry page
Posted by Yury Luneff <bi...@ya.ru>.
>> Yuri,
>> instead of using the /FIleReceiver URL, do construct a URL by using
>> component resources in your page, e.g.
>> FileReceiver...:
>> public String getUploadUrl() {
>> return
>> componentResources.createEventLink("fileUploaded").toAbsoluteURI();
>> }
>> in your page template, use something like this to pass the URL to your
>> applet:
>> <applet .....>
>> <param name="uploadUrl" value="${uploadUrl}" />
>> </applet>
> URL("http://localhost:8080" + getParameter("uploadUrl"), where
> uploadUrl is "/addfiles:fileUploaded" and passed as you proposed,
> triggers just addfiles page (at least, onActivate), but not the event
> fileUploaded. I don't know why.
> Actually, it is no difference in URLs, as the one i did was the same, but
> sure that's more appropriate way.
Sorry, after few more tries, it worked. Thanks for help and
attention!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re[2]: doing post request to a tapestry page
Posted by Yury Luneff <bi...@ya.ru>.
> Yuri,
> instead of using the /FIleReceiver URL, do construct a URL by using
> component resources in your page, e.g.
> FileReceiver...:
> public String getUploadUrl() {
> return
> componentResources.createEventLink("fileUploaded").toAbsoluteURI();
> }
> in your page template, use something like this to pass the URL to your
> applet:
> <applet .....>
> <param name="uploadUrl" value="${uploadUrl}" />
> </applet>
URL("http://localhost:8080" + getParameter("uploadUrl"), where
uploadUrl is "/addfiles:fileUploaded" and passed as you proposed,
triggers just addfiles page (at least, onActivate), but not the event
fileUploaded. I don't know why.
Actually, it is no difference in URLs, as the one i did was the same, but
sure that's more appropriate way.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: doing post request to a tapestry page
Posted by Alex Kotchnev <ak...@gmail.com>.
Yuri,
instead of using the /FIleReceiver URL, do construct a URL by using
component resources in your page, e.g.
FileReceiver...:
public String getUploadUrl() {
return
componentResources.createEventLink("fileUploaded").toAbsoluteURI();
}
in your page template, use something like this to pass the URL to your
applet:
<applet .....>
<param name="uploadUrl" value="${uploadUrl}" />
</applet>
Then, in your page, you can have a handler for the "fileUploaded" event:
// from tapestry-upload, commons
@Property
private UploadedFile file;
// alternatively, use the decoder
@Inject
private MultipartDecoder decoder;
onFileUploaded() {
// do whatever you need here, tapestry-upload seems to work well
String name = file.getName();
// alternatively, using the decoder
file = decoder.getFileUpload("Filedata");
}
Let me know if this works for you.
Cheers,
Alex K
On Fri, Feb 27, 2009 at 3:00 AM, Yury Luneff <bi...@ya.ru> wrote:
> Hello, users.
>
> I'm trying to link a java applet to jetty/tapestry. I need to
> pass data through POST request. I'm doing it like this:
>
> URL url = new URL("http://localhost:8080/FileReceiver");
> System.out.println(url.toString());
> HttpURLConnection connection = (HttpURLConnection) url
> .openConnection();
> connection.setRequestMethod("POST");
> connection.setDoInput(false);
> connection.setDoOutput(true);
> connection.setUseCaches(false);
> connection.setRequestProperty("Content-Type",
> "application/x-www-form-urlencoded; charset=utf-8");
> PrintWriter pw = new PrintWriter(connection.getOutputStream());
>
> and then filling the Pw. I'm not interested in input from
> FileReceiver, so there is a "false" for that.
>
> On the tapestry side i thought it would be possible to handle
> this request somehow defining an event for FileReceiver, such
> as onActivate or FileReceiver:receive onReceive. It reacts on
> browser request, but not mine.
>
> What is the right way of doing this (passing large data by
> POST&java to tapestry application)? commons.httpclient is 50
> times bigger than applet itself :)
>
> --
> Best regards,
> Yury
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>