request parameters from a jsp in java without using servlets - java

I want to request parameters in a java file from a jsp without using servlets. Does anyone know how to do this? I believe its something to do with setting an attribute but I'm new to java so its all a learning game from me. I want to send the lotsize and bedrooms parameters to the java file. My jsp file is shown below and i need to know what to put in my java file in order to retrieve these parameters

If you want this indeed, you should use HTML instead to JSP. For your question, I'm not sure, but I guess, because of the socket is based on the TCP protocol, so you can use a browser as a socket client, use GET or POST request to the socket server, you can enter the socket server's address in browser or submit an HTML form, the socket receives the request and response headers and HTML body to the browser.

Related

java - send a file to client by file URL without download on the server

In my web application I have a link which, when clicked, invokes an external web service to retrieve a download URL for a file.
I need to send back to client the file which is beyond this URL, instead of the download URL retrieved from the web service. If possible, I would also like to do it without having to download the file on my server beforehand.
I've found this question about a similar task, but which used PHP with the readfile() function.
Is there a similar way to do this in Java 8?
If you doesn't even want to handle that file you should answer the request with a redirect (eg HTTP 301 or 302). If you want to handle the file you should read the file in a byte buffer and send it to the client which would make the transfer slower.
Without seeing your implementation so far, this is my best suggest.

how to send file objects to servlet using json

I am new to web programming. My web application can upload files (uploaded by drag and drop method in javascripts ) and i want to retrieve them in servlet using Json . servlet file only needs the contents of the text files to do the calculation.
Can any one suggest how to do this ?
softwares used - netbeans ,tomcat
Thank you.
I'm not quite sure if you mean rendering your files in servlets or actually downloading them from your browser. I'm going to assume you mean rendering them. If so, then what you have to do is set up a URI which is associated with the content you want to render. Let's say this is a simple "hello world" rendering in the browser. what you would do is set up a URI as such:
localhost:3000/helloWorld.html.jsp
What you do on your back end is then wait to receive a http GET request to "/helloWorld.html.jsp" page, and then have your router send over the correct page. Luckily, with tools such as tomcat, the routing from local host is straight forward enough, and as your comments mentioned this is simple enough to do with the ample resources on the web.
Also an important point, you don't need JSON when using servlets (if i understood your problem correctly). If you want to send over data in a JSON format, then all you would do is modify the above steps to listen for "/sendJSON.html.jsp" (this could be an empty jsp), and you send over JSON from your back end in your response.

localhost and AJAX/JQuery

I am very new in AJAX/JQuery. I have problem with following thing. I am hoping to get some information and suggestion on following thing.
I have data real time generated data (eg. xyz) in my localhost server which i have programmed using Java.
My question is
Is it possible to retrieve this data ( i.e. xyz) from localhost server using AJAX/JQuery to JavaScript????
What function does that and how do we do that ?? Plz show me with example..it will be very great help for me
Ajax is something just like common HTTP requests, but it is sent inside your jvascript code and can be moderate with javascript.
Independent of the server side script you have, you can use Ajax to send requests and get responses from that server side application (In server side it can be treated as a simple HTTP reauest).
Finally this is a helpful toturial: W3School Tutorial , and if you are familiar with JQuery or using it in your current project, it is the reference for JQuery Ajax: JQuery.ajax, both with samples.

Run http server proxy in android?

is it possible to create a mini HTTP server that acts as a proxy where i can recieve any requests from a webview and it will pass that request to my http proxy server running inside the app that can then view the raw contents of that request(http headers, bodies etc) and handle it from my own proxy?
I can see that the apahce libraries only contain objects that allow you to create requests and handle responses but not how i can create a mini http server.
Thanks
I don't understand the question fully so here's the question I am going to be answering.
Is it possible to create a HTTP server that allows me to view the source code of a web page.
The answer is: yes.
Since I don't really develop for Android phones, I'm only going to list out what you should do.
So first of all you want to accept a connection from a client. Then you might want to send it back a HTML page containing a form with a website URL field. If you set the method to POST, you will be able to make the URL of any length. Now your server needs to know how to receive the HTTP POST request. I don't really know the HTTP well enough to tell you how the request-response is encoded.

JSP download from intranet

I need to read binary file from intranet http server and get it to download to public.
SCHEMA
intranet file server(Apache)=1 <-->Public http server(Apache Tomcat)=2<-->internet authorized user=3
howto release this without save to filesystem on server 2
Thanks for answers i am new on java.
Sorry for my English.
Use java.net.URL (or another http client) to read from 1 and then print it out (in response to 3).
(In Apache Http Server or Nginx this can be achieved using reverse proxy.)
I can only think of two ways in this situation:
Redirect the internet request to intranet.
In JSP page use:
<% response.sendRedirect("http://intranet_address");%>
or
<c:redirect url="http://intranet_address"/> using standard taglib.
In Servlet page use:
response.setStatus(302);
response.setHeader("Location", "http://intranet_address"); or just
response.sendRedirect("http://intranet_address");
Use a kind of proxy on server 2 to read from server 1 and send directly to internet user without saving to server 2.
I have never tried the first approach on an intranet, but I don't think it would work given the fact the intranet address won't be valid to the internet user.
Now we are only left with the second approach - using a proxy layer. The proxy function could be implemented in many ways: a simple one might be just a bean behind the Servlet to open URL to the file server 1, read file and send it through Servlet response stream to the user or maybe you can use some kind of embedded HTTPClient.
Edit: Since you are going to download binary file, JSP is not a good choice. It's meant to handle textual data. You need Servlet to do binary stream. You can set things like the following on your HttpServletResponse:
resp.setContentType("application/octet-stream");
resp.setContentLength(length);
resp.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"" );
so the content will be send as an attachment with the name you set.

Categories

Resources