how to send HTTP request to a servlet [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to send HTTP request in java?
I only have one servlet running on the Tomcat server side. Now I want to send a HTTP request to this servlet from a Swing application, and it's not an APPLET application (because I see some examples sending request from applet). How can I do this?

While you can open a direct socket connection and send the raw HTTP headers & content and receive a response back, I would urge you to take a look at HttpRequestBase.

Related

Client HTML VS JSP [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Generate an HTML Response in a Java Servlet
(3 answers)
Closed 3 days ago.
I've been getting a good understanding of raw servlets, now, I know that HTML is prebuilt so if the client wanted to make a request to the server for some type of dynamic change, is this where i need to use JavaScript to make that request and do some DOM minuplulations?
Help me understand JSP, so instead of doing that DOM minuplulations with javascript from the client, I can just use JSP on the server and have my servlets build the page on run time then return that jsp back to the client?
Help me undertstand JSP vs HTML on how they differ from client to server
now i know if i make a request to the server for a page it comes back as a html that ive built, to populate the page with data from the server i would need to make request using js then use the response data to make sometype of changes within the clientside, so is this where JSP comes in handy, the work will be done on the server side? all the server got to do is insert the data and return the page?

Getting 400 bad Request with Tomcat 8.5.9 [duplicate]

This question already has answers here:
How to pass a JSON array as a parameter in URL
(9 answers)
Closed 5 years ago.
I'm new to tomcat server technology. Currently I'm working on the spring boot application and I tried calling the below api with the tomcat servers (below 8.5v) running in the background, I got the response as I expected. But when I tried to call the same api with tomcat server 8.5.9v running in the background I'm getting the 400 bad request.
http://localhost:8080/TestRest/ExtractTest?jsonString={"extract":
{"Type":"veswanth", "objects":[{"object":"WTT"}]}}
And in the log file I found the below issue
service Error parsing HTTP request header Note: further occurrences of
HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the
request target. The valid characters are defined in RFC 7230 and RFC
3986
Kindly help me to fix this issue and correct me if did anything wrong..
You can not pass json data in url in that way. You need to pass it in body and request method should be POST.
You can refer this:
How to pass a JSON array as a parameter in URL

how to detect whether request is coming from browser or smartphone? [duplicate]

This question already has answers here:
Detecting Device Type in a web application
(8 answers)
Closed 9 years ago.
I am having a web application , which works fine .
now there is a particular page which gets bulky when i access the application from smartphone browser , so I wanted a situation like
if(request comes from computer browser client )
forward to bulky page in web application
else
if (request comes from smartphone )
forward to some other light page .
please put your suggestion how can i achieve this
Use the user-agent. Every connection to your server carries this header, by convenience and convention. There is no guarantee that a browser will be truthful(such as a spambot reporting itself as Chrome). You can get the user-agent as follows:
request.getHeader("User-Agent");
and then check again known user-agent strings and templates.
It's generally done by checking "User-Agent" header of Request

How to do a POST inside a JSP or Servlet? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use java.net.URLConnection to fire and handle HTTP requests?
I need to do a http post call to an external URL from my servlet. And I need to add some custom http headers too to the message. Is this possible ? please provide me a guidance.
You can try apache HttpClient library.

hitting a URL using java [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
How to send HTTP request in java?
How to use java.net.URLConnection to fire and handle HTTP requests?
using java, how do i hit any url?
for instance, opening of http://www.xyz.com/node1 in a browser will tell xyz.com that node1 is hit.
so in this java program (which sends sms text say 'node1' in example above embedded in the url itself to a sms gateway server)
how do i achieve it without opening any browser or using servlet.
You can use an HttpURLConnection.
But using it directly is overkill if you just want to load the URL in question. This guide shows you how to open a URL.
Basically it boils down to:
URL url = new URL("http://www.xyz.com/node1");
URLConnection conn = url.openConnection();
conn.connect();
//...
The simplest way is to use URL http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html. For more advanced/flexible URL fetching you could use HttpClient http://hc.apache.org/httpclient-3.x/

Categories