cancel
Showing results for 
Search instead for 
Did you mean: 

Servlet aliases

Former Member
0 Kudos

Hello everybody,

I am running WAS 6.40 Snake Preview on MAX DB. I’m trying to use the SAP J2EE engine as a servlet engine.

Everything works fine until I try to implement a servlet which distinguish between servlet __name__ and servlet ___alias___.

Here is a piece of my servlet code:

public class Counter extends HttpServlet{

static int classCount = 0;

int count = 0;

static Hashtable instances = new Hashtable();

……

public void doGet(………){

out.println(count++);

out.println(classCount++);

out.println(instances.size());

}

}

In the web.xml of my Web Module Project in the Mappings tab I’ve entered following:

Servlet Name:Counter URL Pattern: Counter1

Servlet Name:Counter URL Pattern: Counter2.

And calling following URL-s:

URL1: host_name:50000/EAR_project/Counter1

URL2: host_name:50000/EAR_project/Counter2

results in:

URL1

out.println(count++) -> 1

out.println(classCount++) -> 1

out.println(instances.size()) -> 1

URL2

out.println(count++) -> 2

out.println(classCount++) -> 2

out.println(instances.size()) -> 1.

Now my question:

according to the tutorial I’m reading, the instance.size in URL2 should be ____2____. And the count value should be _____1_____.

As I assume, it is not the case, because creating two URL Patterns, didn’t result in creating aliases. So there is only one instance of Counter servlet on the j2ee server.

What’s wrong with my servlet?

Where should I enter those aliases in order to create two instances of my servlet?

Any help appreciated.

Regards

Pawel

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You have to create two servlet declarations in web.xml, which will point to one and the same servlet class.

<servlet>

...

-


<servlet-name>servlet1</servlet-name>

-


<servlet-class><b>class</b></servlet-class>

...

</servlet>

<servlet>

...

-


<servlet-name>servlet2</servlet-name>

-


<servlet-class><b>class</b></servlet-class>

...

</servlet>

<servlet-mapping>

-


<servlet-name>servlet1</servlet-name>

-


<url-pattern>Counter1</url-pattern>

</servlet-mapping>

<servlet-mapping>

-


<servlet-name>servlet2</servlet-name>

-


<url-pattern>Counter2</url-pattern>

</servlet-mapping>

Hope this helps

Best Regards,

Violeta Georgieva

Former Member
0 Kudos

Thnx!

It works fine.

Regards

Pawel

Answers (0)