Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Servlet Context Attributes

Status
Not open for further replies.

rwthAachen

Programmer
Jul 10, 2005
3
DE
Hi
Is there any possible way to access a servlet (public) method or get ServletContext attribute from a stand alone class (running on same machine as servlet).

Thanks in advance !!
if you need more details check further.

~Cheers

Details:
My problem is I am using Ericsson's network emulator. The emulator creates a Http connection to send some data. So I have to use Servlet (to provide Http Compatibility) at client side. and I pass my Handler to servlet through web.xml. servlet unparse the data and feed to handler!!

how can I get the Instance of my Handler ?? my servlet has getHandler method as well as ServletContext attribute for that handler.
But I dont know how to access method from standalone class.
 
In theory you could do , but it would be extremely bad practice.

I don't understand this :

So I have to use Servlet (to provide Http Compatibility) at client side.

Seems odd to me - the only thing that provides HTTP compatibily is sending data that conforms to the HTTP protocol - a servlet by its own will not do this ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi,
Thanks for replying. actually this is a server-server kind of communication.

Here is the server side code ... which creates a Http Connection.. and explicitly send data in HTTP message format.
<URL> is the link of my servlet which receive all packets at other server side.

public void pushReport(String s, ClientBean clientbean)
throws Exception
{
try
{
URL url = new URL(URLDecoder.decode(clientbean.getURL().trim(), "UTF-8"));
HttpURLConnection httpurlconnection = (HttpURLConnection)url.openConnection();
httpurlconnection.setDoOutput(true);
httpurlconnection.setRequestMethod("POST");
httpurlconnection.setRequestProperty("Content-Length", String.valueOf(s.length()));
httpurlconnection.setRequestProperty("Accept", "*.*");
httpurlconnection.setRequestProperty("Content-Type", "text/xml");
sendReport(httpurlconnection.getOutputStream(), s);
httpurlconnection.getInputStream();
}
catch(Exception exception)
{

}
}

I can not change anything but URL Attribute's values. this code is prop. to 3rd party. :/
baffled.
Is there any better approach to handle this data at other side of server. so that I can have full control over Handler class !

Thanks in advance !
~Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top