| Author |
Call servlet from very first JSP
|
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 268
|
|
Hi,
Could you please tell me how to call a servlet from the very first jsp e.g. index.jsp
I need to know what to write in the action parameter of the form tag.
e.g.
does action parameter contain the actual name of the servlet class or something else ?
Also is there anything I need to change in the <url-pattern> tag ?
Please advise.">
|
Thanks,
Pramod
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
First:
Wrong, wrong, wrong!
This will make every request route to your servlet. Every request. Every! Is that what you want?
Second, once you have a valid mapping, the action URL should be the context path followed by the mapping pattern.
The context path can be obtained via the EL expression ${pageContext.request.contextPath}
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Lucas Smith
Ranch Hand
Joined: Apr 20, 2009
Posts: 747
|
|
|
SCJP6, SCWCD5, OCE:EJBD6.
|
 |
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 268
|
|
Hey Lucas,
I guess even /* will do in <url-pattern>, am I right ?
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
pramod talekar wrote:I guess even /* will do in <url-pattern>, am I right ?
Did you read my reply? If you plan to ignore them, just let me know.
|
 |
Lucas Smith
Ranch Hand
Joined: Apr 20, 2009
Posts: 747
|
|
Bear, take it easy. Some users want to get straightforward reply :).
pramod, just use it as I showed you :).
|
 |
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 268
|
|
Hi Bear,
Thanks for your help. Please ignore it.
Lucas, you rock !!!
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
Lucas Smith wrote:Bear, take it easy. Some users want to get straightforward reply :).
And what part of my reply was not straightforward?
Mapping /* will cause all requests to map to the servlet. What is not clear about that?
|
 |
Lucas Smith
Ranch Hand
Joined: Apr 20, 2009
Posts: 747
|
|
|
Everything was crystal clear but pramod expected to get modified piece of his code, I guess :).
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
NotACodeMill
It'd be more instructive to help him work out proper URL mapping than just hand him the code.
|
 |
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 268
|
|
Right Bear.
In my index.jsp , I have just one button, hence I asked for /*.
All I needed was just the action tag setup.
|
 |
Lucas Smith
Ranch Hand
Joined: Apr 20, 2009
Posts: 747
|
|
Bear, I can't agree with you more:
"Give a man a fish and you feed him for a day.Teach a man to fish and you feed him for a life time."
But sometimes, someone wants to get a quick response.
|
 |
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 268
|
|
Right Lucas.
I'm aware of the code, unfortunately forgot the action parameter setting.
Good night.
|
 |
Mariya Antony christopher
Ranch Hand
Joined: Jan 24, 2012
Posts: 47
|
|
pramod talekar wrote:Hi,
Could you please tell me how to call a servlet from the very first jsp e.g. index.jsp
I need to know what to write in the action parameter of the form tag.
e.g.
does action parameter contain the actual name of the servlet class or something else ?
Also is there anything I need to change in the <url-pattern> tag ?
Please advise.">
specify the servlet name in action
<form method="get" action="test">
|
 |
Prasad Krishnegowda
Ranch Hand
Joined: Apr 25, 2010
Posts: 461
|
|
Mariya Antony christopher wrote:specify the servlet name in action
<form method="get" action="test">
No. Its wrong..
Bear and Lucas, have already given an answer.
|
Regards, Prasad
SCJP 5 (93%)
|
 |
 |
|
|
subject: Call servlet from very first JSP
|
|
|