Request.getParameter java to vb.net - java

I have a question about retrieving data from a client who is using java and i am using vb.net.
I am expecting a form posted to me and read the data.
My issues is when i do Request.Form("DATA") i get nothing from the client.
Now if i create a html form and post it to my url with the field "DATA" i can read everything fine. I can also loop through my form and see the field and the button if i right them out to the screen or to a text file. Code is below
response.write(Request.Form("DATA"))
OR
Dim entryName As String
For Each entryName In Request.Form
response.write("Entity Name: " & entryName)
Next
Either method above works fine for me but not for the client. When the client hits my page i see nothing at all no buttons no fields, nothing.
I am concerned he is not posting properly to me. I spoke with the developer and he said he would retrieve the data on his end by doing something like "Request.getparameter"
I do not know java at all but from what i read it sounds like "Request.getparameter" will grab any field out of a form or querysting that has the name specified aka my "DATA" field that i am looking for.
Can anyone explain to me what request.getparameter means in java and what the equivalent code would be in vb.net?
Again i do not know java at all and have searched on this for a while but cant quite find a definitive answer.
Thanks in advance.

It is correct that in Java, request.getParameter("DATA") will look in both the query string and posted form data, while in .NET, Request.Form("DATA") only looks at posted form data. Therefore, it seems likely that your client is sending the data in the query string, since you are not seeing it.
You have a few options. You could use Request.QueryString("DATA") to check only the query string, or either Request.Item("DATA") / Request("DATA") or Request.Params("DATA") to check both the query string and posted form data, plus cookies and server variables. I think Items and Params may be a little different in what they return, e.g. for multiple values. They are probably the closest equivalent to the Java request.getParameter function.

Related

How to get Javascript var value in Java (wicket 6)

I have a fairly simple question, but I'm unable to find a working answer.
I'm using javascript in my HTML file for a page that is taking input from the page and giving me back a string of a jSON object. All that I want to do is take this string and put it in a Java string.
I can do things like
target.appendJavaScript("s=getString();");
target.appendJavaScript("alert(s);")
which give me the desired information in the alert. But how do I get s into a Java string?
I have tried the following
StringValue temp = RequestCycle.get().getRequest().getQueryParameters().getParameterValue("s");
info(temp.toString());
And other variations like getRequestParameters(), but I get nulls on temp.
These actions are inside an AjaxFallbackButton's onSubmit.
Any advice on how to get a javascript var in Java?
Although I would still like to know more about sharing variables between Java and Javascript in HTML, my case was solved thanks to Wicket.
The value that I was retrieving with s=getString() was already accessible in a HiddenField, and so I simply needed to get it a wicket:id in the HTML and add it with a property model in the Java. Hopefully this might help someone else in the future.

Read and Analyze Data on another webpage and insert onto mine

Im trying to make a simple webpage which obtains football league table data
http://www.skysports.com/football/league/0,19540,11660,00.html
For example i want to read in the points column and divide it by the number of games played to get an average points per game column that i will print onto my webpage.
How can i do this online?
Im quite experienced at doing this with offline programmes such as C/Matlab but i dont know where to start with it online.
Thanks
I wouldn't suggest to do it client side (on browser). It will be easier to scrap on server side (using java for example) following the steps:
Grab the content of the webpage (skysports)
Use existing html markup with regex to locate the desired content part.
Strip/split html markup with regex to get records (tr) and fields (td).
Cast values and do your math.
Use results to generate your version of html or json or whatever.
Serve the generated content to your client.
In general scrapping is easy but not guaranteed for tomorrow as source html markup may change at any time (and without warning).
I can provide a basic sample in C# if you want. (Sorry I haven't "java" since 1997).
You use jQuery.get like this:
$.get('http://www.skysports.com/football/league/0,19540,11660,00.html', function(data) {
//do the parsing here
});
There are several programing languages capable of getting at this information, PHP would be the classic method using curl or file_get_contents and regex parsing to extract the bits you want. You could do it with Yahoo Pipes as well if your web host does not allow remote URL retrieval.
If none of the Java brigade come back with something better contact me and I'll do some rough code for you in PHP.

How do I send a query to a website and parse the results?

I want to do some development in Java. I'd like to be able to access a website, say for example
www.chipotle.com
On the top right, they have a place where you can enter in your zip code and it will give you all of the nearest locations. The program will just have an empty box for user input for their zip code, and it will query the actual chipotle server to retrieve the nearest locations. How do I do that, and also how is the data I receive stored?
This will probably be a followup question as to what methods I should use to parse the data.
Thanks!
First you need to know the parameters needed to execute the query and the URL which these parameters should be submitted to (the action attribute of the form). With that, your application will have to do an HTTP request to the URL, with your own parameters (possibly only the zip code). Finally parse the answer.
This can be done with standard Java API classes, but it won't be very robust. A better solution would be HttpClient. Here are some examples.
This will probably be a followup question as to what methods I should use to parse the data.
It very much depends on what the website actually returns.
If it returns static HTML, use an regular (strict) or permissive HTML parser should be used.
If it returns dynamic HTML (i.e. HTML with embedded Javascript) you may need to use something that evaluates the Javascript as part of the content extraction process.
There may also be a web API designed for programs (like yours) to use. Such an API would typically return the results as XML or JSON so that you don't have to scrape the results out of an HTML document.
Before you go any further you should check the Terms of Service for the site. Do they say anything about what you are proposing to do?
A lot of sites DO NOT WANT people to scrape their content or provide wrappers for their services. For instance, if they get income from ads shown on their site, what you are proposing to do could result in a diversion of visitors to their site and a resulting loss of potential or actual income.
If you don't respect a website's ToS, you could be on the receiving end of lawyers letters ... or worse. In addition, they could already be using technical means to make life difficult for people to scrape their service.

array data populating issues with Javascript

I have a array of data which was generated due to some Actions in my previous actions
On submitting that page, Control will be redirecting to the second page,
IN the second page, I need to populate the array data into the Tables
( I want to use Javascript to populate this, No other means)
Problems which i am facing now
1) I cant read the Java array in the Java script ? (I am not sure how to pass the Java array to Javascript function)
2) Thought of implementing the Java script objects similar to the java objects, but there will be lot of over head
Can any one help me to over come this situation
I am using the BTT framework which is similar to Struts, for Javascript I am not using any frameworks
Thanks in advance
JSON would be a format to make the java-array accessible in javascript.
https://github.com/douglascrockford/JSON-java/blob/master/JSONStringer.java
too broad to answer, since specifics are missing. here are some generic steps.
Collect your stuff in JavaScript array
Have a hidden form field
while posting to server, set the value of hidden field to your array (in string format)
Read the hidden field content in server (posted form data)
Parse them (JSON is appropriate here)
Use them while preparing next page content as JS Array

Java getQueryString

So i'm trying to capture a certian section of a getQueryString(). I know I could try and go through and parse the string to get the certain section I wanted but was hoping to just be able to grab the piece I need.
Here is my query result:
N=0&Ntk=General&Ntt=info&Nty=1&D=info&Ntx=mode+matchallpartial&Dx=mode+matchall
I'm looking just to capture this part: Ntt=info
The =info part will change to whatever the search requested was.
I have gone through a lot of the API request function and haven't found anything that works for me.
Am I just going to have to parse it?
Use ServletRequest.getParameter
req.getParameter('Ntt');
It will return null if the parameter isn't set.

Categories