GeeCON Prague 2014*
The moose likes JSP and the fly likes action attribute in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "action attribute in JSP" Watch "action attribute in JSP" New topic
Author

action attribute in JSP

Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hi ,
I have a following line in a JSP. CrdServlet is subclass of a class named ControllerServlet and LoginHandler is a subclass of class named RequestHandler.

<form name="loginForm" method="post" action="CrdServlet/LoginHandler">

Can somebody tell me what above line means and how is it diffrent from
<form name="loginForm" method="post" action="LoginHandlerServlet"> ?? I want to know how you can specifiy 2 arguments in action attribute of form tag.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Anand Gondhiya:
I want to know how you can specifiy 2 arguments in action attribute of form tag.


You can't. You can only specify one URL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Thanks for your post.

but what does the following mean ?
<form name="loginForm" method="post" action="CrdServlet/LoginHandler">
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

That greatly depends upon the mapping definitions in the deployment descriptor (web.xml). Care to give us a look at it?
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Sure. Here is web.xml. From what I understand , it maps CrdServlet/* (and thus CrdServlet/LoginHandler ) to CrdServlet , correct ??

<web-app id="WebApp">
<display-name>CRDWeb</display-name>
<servlet>
<servlet-name>CrdServlet</servlet-name>
<display-name>CrdServlet</display-name>
<servlet-class>com.jpm.crd.servlet.control.CrdServlet</servlet-class>
<init-param>
<param-name>crd.ini</param-name>
<param-value>/WEB-INF/crd.ini</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CrdServlet</servlet-name>
<url-pattern>/CrdServlet/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Chetan Chauhan
Greenhorn

Joined: Oct 03, 2006
Posts: 8
Hello Anand, You have asked the difference between these two statements:

<form name="loginForm" method="post" action="CrdServlet/LoginHandlerServlet">

<form name="loginForm" method="post" action="LoginHandlerServlet">

1st statement specifies the complete path of LoginHandler. CrdServlet is also the name of the project, it seems from web.xml file.
While 2nd statement assumes that LoginHandler is in the current working directory.
If you write LoginHandler in some other directory say, xyz/LoginHandler then you have to specify its path as

xyz/LoginHandlerServlet OR
CrdServlet/xyz/LoginHandlerServlet

in the action attribute.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Chetan Chauhan:

If you write LoginHandler in some other directory say, xyz/LoginHandler then you have to specify its path ...


No, that is all incorrect. The actual path in the folder structure has nothing to do with the mappings as defined in the web.xml.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Anand Gondhiya:
From what I understand , it maps CrdServlet/* (and thus CrdServlet/LoginHandler ) to CrdServlet , correct ?


Yes, although you might run into difficulties omitting the leading /.
 
GeeCON Prague 2014
 
subject: action attribute in JSP