• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet 3.0 annotations and web.xml welcome-file tags

 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a Servlet assignment where the servlet annotations are in the servlet file so there is no web.xml. To use a non-standard welcome-file I have made a web.xml with only the welcome-file tags in it but the web app ignores the web.xml. If I add an index.jsp or index.html to the project it loads fine. If I type the name of the welcome file into the URL the project is fine, it just won't initialize on the non-standard jsp file. The project works and the pages and servlets call each other correctly I just can't get the opening page to be called.





The url works fine



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try /login.jsp
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try /login.jsp


does not work.

I confirmed that the change in the web.xml did get deployed to tomcat.
 
Paul Clapham
Sheriff
Posts: 21878
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
margaret gillon wrote:The project works and the pages and servlets call each other correctly I just can't get the opening page to be called.


So what happens instead?
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To verify whether the web.xml is being loaded, add a display-name element, such as:

<display-name>My Fabulous Web App 1.0.0</display-name>

Restart the web app, and see if the display name shows up in the list view of the Tomcat Manager application.

I also assume you've checked the logs?

Another thought (grasping at straws): you've got a lot of whitespace in there. I have no idea if it's significant or not, but I'd format it as:without all that extraneous whitespace.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the localhost access log


Bear, I took out the white space and added the <display-name>My Fabulous Web App 1.0.0</display-name> line to the web.xml , then I rebuilt the war and redeployed. No difference on what I'm seeing.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I double checked and the web.xml was in the wrong directory when the war unpacked. In the Tomcat directory I manually moved the web.xml to the correct sub directory and restarted the app. Now I see the display name in the Display Name column of the tomcat manager app but the application is still not loading the login.jsp and it gets the error when I open it from the tomcat manager that is showing the display name.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, the web.xml works now. I wiped it out from tomcat and made sure there were no extra web.xml anywhere in the subdirectories. Fixed the build.xml so the web.xml was built into the correct directory in the war file, rebuilt the war, and then restarted everything, again. Now I have the Display Name in the tomcat manager AND the app loads correctly launching the login.jsp. As always Thanks, Bear.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noooooooooooooo!!!



The right page (login.jsp) loads when the project opens but all the @WebServlet annotations don't work and when I submit the login tomcat cannot find the servlet. It seems like tomcat will use the web.xml OR the servlet annotations but won't work with both.... it's not fair........
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I do not believe that is supposed to be the case. (Not a Servlet 3 user.)

Are there structural issues with the remainder of the app?
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is an odd project. It is for the Cattle Drive. I had to take the instructor's solution from the Videos 4a assignment and modify it by adding more classes and forcing a user login and security routines. The classes are inner classes. The project uses the javaranch.actionServlet class.

This morning I added the servlet mapping to the web.xml and the project runs as it should.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My nitpicker had me try using the servlet as the welcome file and that works fine with the @WebServlet annotation.

the annotation


the web.xml


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!