reset password
Author Message
cbort
Posts: 95
Posted 20:08 Apr 16, 2011 |

I made a copy of the package I turned in for homework 2 and changed the URL patterns of all of my links. It is running fine when I run it locally, but when I try to run it on the server after uploading it i get the 404 requested resource is not available error ...


Is it not possible to have to servlets with the same file name and different packages on 1 server?

should I just delete the older ones?

mbuisin
Posts: 16
Posted 21:04 Apr 16, 2011 |

Did you write @WebServlet declarations on the java files or did you manually edit the web.xml file for URL mappings?

What I found easier to implement is to have the hw2 files (some with same filenames) in a subpackage of the original package. Then just add an extension to the original package declaration statement (e.g. cs320answers.hw2). That way I can preserve the structure of the web application as it evolves in subsequent homeworks. I just needed to make sure that the @WebServlet declarations (for URL mappings) is updated.

cbort
Posts: 95
Posted 21:30 Apr 16, 2011 |

I did @webservlet declarations... do i need to do web.xml?

cysun
Posts: 2935
Posted 23:17 Apr 16, 2011 |

I'm not quite sure what you mean by "I made a copy of the package ...". I assume you are trying to deploy both hw1 and hw2 on CS3 at the same time, which is OK as long as you don't have conflicting servlet mappings.

Suppose you have a servlet hw1.ListQuestions for HW1 and a servlet hw2.ListQuestions for HW2. It's OK that they both have the same class name because they are in different packages; however, it is not OK if both of them have the servlet mapping @WebServlet("/ListQuestions"). When conflicting servlet mappings like this exist, Tomcat won't be able to load the application thus the 404 error. To avoid this problem, simply make sure the servlet mapping is unique, e.g. use @WebServlet("/hw1/ListQuestions") and @WebServlet("/hw2/ListQuestions") instead. I think this is also what MBUISIN is suggesting.