File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Determine Which Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Determine Which Form" Watch "Determine Which Form" New topic

Determine Which Form

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I have 2 relativly similar JSP's that are sharing a common servlet because of a specific task that they perform. However, depending on which form called the servlet, I need to forward to a different page.

I know how to determine which Button was pressed and for all intent and purposes I could just name the buttons on both pages differently and check for that, however, is there a way to retrieve the calling form in a servlet?

GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

No. The form name is a client-side element that is not passed to the back end. You could do the button thing or better yet, include a hidden parameter in the form. I prefer the latter because it's a purer "API" than relying on client-side artifacts such as button names.

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Ditto for the hidden field

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Thanks guys.
I agree. Here's the link:
subject: Determine Which Form
It's not a secret anymore!