cancel
Showing results for 
Search instead for 
Did you mean: 

servlet ----->url association ?

Former Member
0 Kudos

Hi All,

I have created a simple java servlet using the J2EE perspective of SAP NetWeaver Developer studio. Now how will I invoke this servlet ? I mean how, an url is associated with this servlet.

I hope my question is clear.

Thanks and regards,

Loveline.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hey Loveline,

o.k. I try to keep this short, you can find a more extensive description in a number of webserver documentations.

First of all, it is a bit unclear are you asking in general how URL's are associated with servlets or are you interested more in just knowing how you run one within the Developer studio. I assume for this that you are insterested in the more generic "how to run a servlet".

First of all, a servlet is part of a webapplication which is run by a servlet container (for example WAS 6.20 contains one and Tomcat is one). A webapplication must follow a certain standard folder structure and most importantly it must contain a file called web.xml which is the source for a lot of things.

A webapplication has a name which is basically the root folder name and this is know on the server as the context root.

For example. You have a webapplication called myApp hence the url to this would be http://server:port/myApp/

To access a servlet on this you need to define somewhere (in tomcat for example server.xml) what url pattern will invoke the servletdispatcher. The servlet dispatcher is then the actual servletrunner that will execute the sevlets java code and spit out, for example html.

In the web.xml file above you can also further define servlet specific mappings where you have to define the name of the servlets class file, a logical name for it and an url mapping to match with the logical name.

For example you could define that you want to execute your servlet TestServlet by passing in /servlets/TestServlet

this would then translate to http://server:port/myApp/servlets/TestServlet

For the sake of not repeating too much of commonly found descriptions I would suggest that you look at the following http://www.developer.com/java/ent/article.php/2178651

it is quite a long article, but it gives you reasonable answers regarding the basics of servlets.

If you just want to ignore this part and just configure your Studio to execute the servlet without you knowing too much what actually happens then specify

My apologies if I went in a completely wrong direction with this, but your question was a bit open ended.

Cheers,

Kalle

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Ivaylo,

Thanks a lot. Now I am able to run the servlet. Kalle had already mentioned it, but it did not click me.

Thanks and Best Regards,

Loveline.

Former Member
0 Kudos

Hello Ravi,

Thanks for the suggestions. I have tried both. In the just previous mail I have given the steps that I have taken. Is there anything that I am missing ? How will I know the port number, to be specified in the url ?

Thanks and regards,

Loveline.

Former Member
0 Kudos

Hello Kalle,

First let we say "Thank you". I want to know how I can run a servlet in SAP NetWeaver Developer studio. I will tell you the steps I have taken in the developer studio.

1. I created Web module project.

2. Then created a servlet in it.( Myservlet )

3. Then I build a WAR file.

4. Then I created a Enterprise Application Project, in order to deploy it.

5. I edited the application.xml file, gave context root a value Myfirstservlet.

6. Then I build the EAR file and deployed it.

Now I want to run the servlet,

I gave

http://sapep:50000/servlet/Myservlet Error : File not found

I tried the following also

http://sapep:50000/Myfirstservlet

Is there anything that I am missing here. How will I know the port number I should give ?

Thanks and Regards,

Loveline.

Former Member
0 Kudos

Hi Loveline,

you need only to map your servlet to a URL pattern in order to call it (as Kalle also mentioned in his post). I'll just tell you how to do that in the Developer Studio. Find it below in between your steps.

>

> 1. I created Web module project.

> 2. Then created a servlet in it.( Myservlet )

Open the web.xml node under your Web Module project (doble-click on it). Open the Mappings tab. Specify the URL pattern and map it to your servlet (let's assume you map the servlet to the URL pattern <i>servlet</i>). Here is a description of the procedure in the documentation: http://help.sap.com/saphelp_nw04/helpdata/en/b6/e8b48a76b17b449c07cb5edbdf152b/frameset.htm

Save the changes.

> 3. Then I build a WAR file.

Rebuild your WAR.

> 4. Then I created a Enterprise Application Project,

> in order to deploy it.

> 5. I edited the application.xml file, gave context

> root a value Myfirstservlet.

> 6. Then I build the EAR file and deployed it.

Rebuild the EAR too. Deploy the new EAR to the J2EE Engine.

>

> Now I want to run the servlet,

Now, to call your servlet, enter the following URL:

http://sapep:50000/Myfirstservlet/servlet

Former Member
0 Kudos

Hi Thomas,

If you want to invoke the servlet. First you need to run this servlet on a server. Then access this <application>.java using

http://localhost:port/<application>;

port should be some default port number that comes with the NetWeaver. The servlet has a .java extension, but when accessing the servlet from the server you do not call the with .java extension. you just invoke it by the name of the servlet.

If you are still not able to access it, then try giving the relative location of the servlet like

http://localhost:port/<application-parent>/<application>;

Ravi