1

Say for example I have a servlet named FooServlet, mapped to /foo.

There are two other servlets named BarServlet and CarServlet, mapepd to /bar and /car, respectively.

Now, if a user does a direct access to www.example.com/foo, they should be rejected. BUT if the request comes from a forward on /bar or /car, I will allow access to /foo.

Is this possible?

Jekk
  • 577
  • 8
  • 27

2 Answers2

1

Yes, see this question: Java get referer URI?

You can check the referer header in the request to make sure they are coming from one of your other servlets.

Community
  • 1
  • 1
Rick Mangi
  • 3,761
  • 1
  • 14
  • 17
1

You can use the request object to decide. For ex :

Use request.getContextPath() to fetch the "/foo", "/bar" or "/car" and decide whether to allow the access or not.

Vimal Bera
  • 10,346
  • 4
  • 25
  • 47