• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

not able to set the url pattern

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
As in HFJS book chapter 3, im trying set the <url-pattern> to something like 'SelectBeer.do" . But i am not able to set the url-pattern to anything except the actual servlet class name. When i run the web app(the same web app described in chapter 3, the beer advisor web app) after i click the submit button it goes to the url which ends with the servletclassname. i.e. http://localhost:8080/BeerV1/BeerSelect. i changed the action atttribute value in the form.html to 'selectbeer.do'.see my web.xml also.

please suggest me what is wrong here.

Thanks,
Teena
 
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you post the form.html content too

Regards,
Ranil
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response. I think you can help me out since you are SCWCD! so you might have tried the same example in chapter3.
Hmm..
right now i can't as im from a different place now. but i can assure you that i copied the same form.html code from the book.(Chapter 3 HFSJ)
is it dependant on the SDK version? i have netbeans 5.5.1 which takes jdk1.4, not 1.5. is this a reason?
Ok, i remember it..
the html starting from <form>...

<form method="POST" action="selectbeer.do">
Select Color:
<select name="color" size="1">
<option value="light">light</option>
<option value="amber">amber</option>
</select>
</form>
</body>
</html>

Hope i provided you some details
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Teena George:
i have netbeans 5.5.1 which takes jdk1.4, not 1.5. is this a reason?
Ok, i remember it..
the html starting from <form>...

<form method="POST" action="selectbeer.do">
Select Color:
<select name="color" size="1">
<option value="light">light</option>
<option value="amber">amber</option>
</select>
</form>
</body>
</html>



1.netbeans5.5 support jdk1.5

2.where is the submit button for your form?

3.if you want to try HeadFirst Concept try with simple program.
whether headfirst explain in struts?
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Teena,

It looks like to me that the code written for the form.html is not complete. As it is pointed out you got to place the submit button too. If you have not placed that in the actual code that you used in testing please do so first and retry again.Assuming that you have a submit button at the right place in the code of form.html the request which would be generated by the browser has to point to the following url, http://yourserverip ort/approot/beerselect.do.

And the web container first look for an exact match , folder match and then extension match in the web.xml file. In this case it seems to me that there is an exact match and extension match too. exact match takes the precedence over extension match then. Hence your application must be mapped to /beerselect.do , which in turn maps it self to BeerSelect servlet.

Please do try the example again and keep posted the updates.


Hope this helps

Regards,
Ranil
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, i included the submit button in form.html, but i forgot to add that while posting. The submit button is placed correctly. the problem is when i click on the submit button it goes to the /BeerSelect servlet not the beerselect.do(which is again the servlet). i dont know why it checks for the servlet name instead of the url-pattern i gave. apart from web.xml and the form.html, are there any places where i can change this? i dont understand the exact mach and extension match concept. is it because i used the same name for the servlet and the url-pattern? is it case sensitive?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a little confused myself - can you clarify what you are expecting to happen, and what is actually happening!

In your web.xml (I presume this is the one in the <tomcat-path>\webapps\Beer-v1\WEB-INF\) you have the following:


So anything posted to /selectbeer.do will be matched against the servlet-name BeerSelect which in turn is mapped to the servlet com.example.web.BeerSelect (i.e. <tomcat-path>\webapps\Beer-v1\WEB-INF\classes\com\example\web\BeerSelect.class).

So the other BeerSelect servlet you mention in your posting - how is this defined and where is it? Why have two servlets with the same name??

The other thing worth checking is caching issues - both the browser and the container may be caching previous versions of "faulty" code.

View the source of your form in the browser and make sure it's as you expect - if not try a Ctrl F5 (assuming IE). Try restarting your container to make sure it's picking up any changes you make to web.xml etc.

HTH - Rufus.
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Teena ,

Yes , I would also suggest you to clear the browser cache and also the stuff in the tomcat's work folder.

Regards,
Ranil
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you all for the responses. the problem was in using the same name for the servlet and for the url pattern. when i changed the url-pattern to another unrelted name, it worked.

Thank you again,
Teena
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Teena,

I would like to point that using the same name for both url-pattern , servlet class would not make any issue. For example you could have

<servlet>
<servlet-name>BeerSelect</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>BeerSelect</servlet-name>
<url-pattern>/selectbeer.do</url-pattern>
</servlet-mapping>

in web.xml file and it works. (I guess you are talking about servlet-name being the same as the servlet class name )

also following mappings are working as well

<servlet>
<servlet-name>BeerSelect</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>BeerSelect</servlet-name>
<url-pattern>/BeerSelect.do</url-pattern>
</servlet-mapping>

Hope this is helpful!

Regards,
Ranil
[ October 08, 2008: Message edited by: Ranil Liyana Arachchige ]
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranil,
Actually my problem was with the second way. when i used



the url in the address bar was ../BeerSelect not the expected ../beerselect.do
i doubt this is the expected result as you suggested(exact match and extension match)
see that i used full lower case letters for the urlpattern.
will that effect the result?

Thanks,
Teena
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Teena,

Yes , it effects. The url that you are trying to access must resolve to an available url mapping in web.xml. so that if you want to access /selectbeer.do , then the form must be submitted to "selectbeer.do" not "SelectBeer.do". You may be able to get a good understand on URL mapping rules by referring to HFSJ 2nd Edition , page 616 onwards.

hope that helps you

Regards,
Ranil
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranil,
Now everything works fine.
these are the scenarios i tried:

Everything works fine. as far as i know, the url-pattern in web.xml and the value of the action attribute in the form.html should be the same including letter casing.

Thanks again,
Teena
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
great !!! good luck with the work
 
This tiny ad is wafer thin:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic