This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes Call servlet from very first JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Call servlet from very first JSP" Watch "Call servlet from very first JSP" New topic
Author

Call servlet from very first JSP

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

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 ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

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}


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1





SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hey Lucas,

I guess even /* will do in <url-pattern>, am I right ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

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: 804
    
    1

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: 323

Hi Bear,

Thanks for your help. Please ignore it.

Lucas, you rock !!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

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: 804
    
    1

Everything was crystal clear but pramod expected to get modified piece of his code, I guess :).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

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: 323

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: 804
    
    1

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: 323

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: 49

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: 539

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Call servlet from very first JSP