I have a .jsp page from a third party i need to get information from.My application is being developed in MVC4. how will i get information from this .jsp file in my application.
I tried using webrequest but the content is not there.
Regards Fatema
I have a .jsp page from a third party i need to get information from.My application is being developed in MVC4. how will i get information from this .jsp file in my application.
I tried using webrequest but the content is not there.
Regards Fatema
The JSP-page has to be actually rendered by a Servlet-Container like tomcat because the containing data are dynamical. Done so you can parse the HTML-output with your .net-application.
This might be the only way. To read the data directly from the jsp.
Anyway I suggest you find another way to retrieve the data like adding an API to you Java EE-application that the jsp is part of. Or access an existing one.
I think you have two options:
The first option is to do this on the client side using Ajax: (http://api.jquery.com/jQuery.ajax/
Code could look something like:
function CallOtherSite(otherSiteUrl) {
$.ajax({
url: otherSiteUrl,
cache: false,
success: function (html) {
//This will be the html from the other site
//parse the html/xml and do what you need with it.
}
});
Because this is done with JavaScript on the client side you will most likely run into a problem with CORS. (http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx)
The other option and better option in my opinion is to do this on the server side. (Either in a controller or view with Razor) (It will be much easier in the contoller...)
try
{
var request = (HttpWebRequest)WebRequest.Create(urlToOtherSite);
request.Accept = "application/xml";
request.Method = "GET";
webResponse = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(webResponse.GetResponseStream());
string responseText = sr.ReadToEnd();
}
catch(Exception ex)
{
}
finally
{
if (sr != null) { sr.Close(); }
if (webResponse != null) { webResponse.Close(); }
}
Then you can use the StreamReader to get the html/xml and do what you will with it.
Hope this helps...