Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Problem with tomcat 6.0.32 (http://www.velocityreviews.com/forums/t951840-problem-with-tomcat-6-0-32-a.html)

ruds 09-05-2012 06:50 AM

Problem with tomcat 6.0.32
 
hi,
I'm am deploying an application having JSP's and few servlets. My servlet is not getting invoked after calling from JSP. My web.xml entry is:
<web-app>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>CheckLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/CheckLogin/* </url-pattern>
</servlet-mapping>
</web-app>

all my classes are in the WEB-INF/classes directory. On called by JSP I'm getting error as:
The requested resource (/CheckLogin) is not available.
I'm calling this from a JSP form element:
<FORM name="f1" ACTION="/CheckLogin" METHOD=POST onsubmit='return checkall()'>

please tell what might be causing this problem.
Thanks in advance.


markspace 09-05-2012 04:03 PM

Re: Problem with tomcat 6.0.32
 
On 9/4/2012 11:50 PM, ruds wrote:
> hi,
> I'm am deploying an application having JSP's and few servlets. My servlet is not getting invoked after calling from JSP. My web.xml entry is:
> <web-app>
> <servlet>
> <servlet-name>login</servlet-name>
> <servlet-class>CheckLogin</servlet-class>
> </servlet>
> <servlet-mapping>
> <servlet-name>login</servlet-name>
> <url-pattern>/CheckLogin/* </url-pattern>
> </servlet-mapping>
> </web-app>
>
> all my classes are in the WEB-INF/classes directory. On called by JSP I'm getting error as:
> The requested resource (/CheckLogin) is not available.
> I'm calling this from a JSP form element:
> <FORM name="f1" ACTION="/CheckLogin" METHOD=POST onsubmit='return checkall()'>
>
> please tell what might be causing this problem.



What is the context path for the web app? Can you show us the URL used
for the FORM above, and the URL of the /CheckLogin action that doesn't
work? Just cut and paste them both from the browser, don't try to
"figure them out." I want the host name too, even if it's "127.0.0.1"
or localhost.






ruds 09-06-2012 03:36 AM

Re: Problem with tomcat 6.0.32
 
the URL for my webapp is: http://localhost:8080/FIR/login.jsp
the URL which it gets directed to should be: http://localhost:8080/FIR/CheckLogin
but it is going at: http://localhost:8080/CheckLogin

Fredrik Jonson 09-06-2012 04:36 AM

Re: Problem with tomcat 6.0.32
 
In <5f8ee108-bcec-4f96-ac86-d49e548b204a@googlegroups.com> ruds wrote:

> I'm am deploying an application having JSP's and few servlets. My servlet is
> not getting invoked after calling from JSP. My web.xml entry is:
>
> <servlet-mapping>
> <servlet-name>login</servlet-name>
> <url-pattern>/CheckLogin/* </url-pattern>
> </servlet-mapping>
>
> I'm calling this from a JSP form element:
> <FORM name="f1" ACTION="/CheckLogin" METHOD=POST onsubmit='return checkall()'>


You need to prepend the servlet context path to the form action url.

In html, when you specify a relative url that starts with a / it is
interpered as being relative to the server root. So /foo is interpreted
as http://example.com/foo. The servlet mapping in web.xml does normally
not start from the server root, but from the servlet context path.

--
Fredrik Jonson

markspace 09-06-2012 05:27 AM

Re: Problem with tomcat 6.0.32
 
On 9/5/2012 8:36 PM, ruds wrote:
> the URL for my webapp is: http://localhost:8080/FIR/login.jsp
> the URL which it gets directed to should be: http://localhost:8080/FIR/CheckLogin
> but it is going at: http://localhost:8080/CheckLogin
>



Yup, c.f. Fredrik's reply: the "action" from the form needs to either be
/FIR/CheckLogin, or it needs to be a relative URL -- "CheckLogin" with
no slash in front.

Your missing the context path, in other words, which is easy for newbies
to trip on.



Arne Vajh°j 09-09-2012 02:33 AM

Re: Problem with tomcat 6.0.32
 
On 9/6/2012 12:36 AM, Fredrik Jonson wrote:
> In <5f8ee108-bcec-4f96-ac86-d49e548b204a@googlegroups.com> ruds wrote:
>
>> I'm am deploying an application having JSP's and few servlets. My servlet is
>> not getting invoked after calling from JSP. My web.xml entry is:
>>
>> <servlet-mapping>
>> <servlet-name>login</servlet-name>
>> <url-pattern>/CheckLogin/* </url-pattern>
>> </servlet-mapping>
>>
>> I'm calling this from a JSP form element:
>> <FORM name="f1" ACTION="/CheckLogin" METHOD=POST onsubmit='return checkall()'>

>
> You need to prepend the servlet context path to the form action url.


Or drop thw / entirely.

> In html, when you specify a relative url that starts with a / it is
> interpered as being relative to the server root. So /foo is interpreted
> as http://example.com/foo. The servlet mapping in web.xml does normally
> not start from the server root, but from the servlet context path.


That is almost certainly the problem.

But may I use the opportunity to mention that it should not be:

action="CheckLogin"

but:

action="<%=response.encodeURL("CheckLogin")%>"

to work with cookies disabled.

Something that is often forgotten today.

An even better solution would probably be to use a taglib that
handles all that stuff for one, but then we are somewhat changing
topic.

Arne




markspace 09-09-2012 03:22 AM

Re: Problem with tomcat 6.0.32
 
On 9/8/2012 7:33 PM, Arne Vajh°j wrote:

> action="<%=response.encodeURL("CheckLogin")%>"
>
> to work with cookies disabled.
>
> Something that is often forgotten today.



Huh, I must be missing something. "CheckLogin" is a hard-coded string
that plainly needs no encoding. What is it that I don't see?




Arne Vajh°j 09-09-2012 03:25 AM

Re: Problem with tomcat 6.0.32
 
On 9/8/2012 11:22 PM, markspace wrote:
> On 9/8/2012 7:33 PM, Arne Vajh°j wrote:
>
>> action="<%=response.encodeURL("CheckLogin")%>"
>>
>> to work with cookies disabled.
>>
>> Something that is often forgotten today.

>
> Huh, I must be missing something. "CheckLogin" is a hard-coded string
> that plainly needs no encoding. What is it that I don't see?


That encodeURL adds the session id to the URL if the browser
does not support cookies (or if it is unknown whether it support
cookies).

Arne



Arne Vajh°j 09-09-2012 03:30 AM

Re: Problem with tomcat 6.0.32
 
On 9/8/2012 11:25 PM, Arne Vajh°j wrote:
> On 9/8/2012 11:22 PM, markspace wrote:
>> On 9/8/2012 7:33 PM, Arne Vajh°j wrote:
>>
>>> action="<%=response.encodeURL("CheckLogin")%>"
>>>
>>> to work with cookies disabled.
>>>
>>> Something that is often forgotten today.

>>
>> Huh, I must be missing something. "CheckLogin" is a hard-coded string
>> that plainly needs no encoding. What is it that I don't see?

>
> That encodeURL adds the session id to the URL if the browser
> does not support cookies (or if it is unknown whether it support
> cookies).


It is well documented:

http://docs.oracle.com/javaee/6/api/...lang.String%29

but the cookies disabled scenario is not much on the radar
screen today.

Arne



markspace 09-09-2012 03:36 AM

Re: Problem with tomcat 6.0.32
 
On 9/8/2012 8:25 PM, Arne Vajh°j wrote:
> On 9/8/2012 11:22 PM, markspace wrote:
>> On 9/8/2012 7:33 PM, Arne Vajh°j wrote:
>>
>>> action="<%=response.encodeURL("CheckLogin")%>"
>>>
>>> to work with cookies disabled.
>>>
>>> Something that is often forgotten today.

>>
>> Huh, I must be missing something. "CheckLogin" is a hard-coded string
>> that plainly needs no encoding. What is it that I don't see?

>
> That encodeURL adds the session id to the URL if the browser
> does not support cookies (or if it is unknown whether it support
> cookies).


Ah right, I knew that, but I haven't used JSPs in so long I'd forgotten
it. Thanks!





All times are GMT. The time now is 01:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.