I'm developing a web application focused in DB managing. For that, I'm trying to be as strict as I could with the MVC model.
I've created some jsp templates for the different objects hold by the DB. e.g, I have a JSP called "competition.jsp" where I show all the details stored about a sport competition. I reach this page from a link, passing as parameter the competition ID to the servlet, which creates a JavaBean with the data from the DB associated with this competition ID and redirect it to the "competition.jsp" in order to show the data. So, in the browser I get a page named "www.example.com/servlet/competition.jsp", which will be the same for all the different competitions.
The problem is that I think having different URLs for different competitions is quite a lot important. I rejected adding a key to the query like "www.example.com/servlet/competition.jsp?id=123", would prefer to have an URL like "www.example.com/servlet/competitions/world-cup.jsp" or "www.example.com/servlet/competitions/world-cup.html", so I thought about generate a new HTML file from the "competition.jsp", calling it "world-cup.html".
It would be a good practice? Which could be the best practice in this case? Remember that I'm using the MVC pattern.
Simplifying, I'm doing something like that at now:
Then in the servlet, I instantiate a bean with the data from de DB, set it as session attribute and redirect to "competition.jsp":
And finally, I show the data of the competition using JSTL:
Yes, I already knew that's not professional using the word "servlet" in the URL, it was only for illustrate the example. I heard something about REST, I will take your advice and take a look about this!
I'm doing that you said, trying to implement a friendly URL pattern in my application. I'm doing it with a Filter that parses the URL into attributes and then forwarding to the servlet.
But now, my problem is different. I added it in my web.xml:
So the script or stylesheet requests will pass another time across the filter, because the <url-pattern> is "/*". I was thinking in a solution for that (defining another filter, using differents url-patterns...) but I don't know what is the most correct and easy way to solve it. Can anyone help me?
Of course, you are right once more... redifining the estructure of the projec was sufficient (I had a very basic structure because those are my firsts steps with the project). Anyway, maintaining the relatives URLs in the project (mainly in <c:import> tags) seems to be so difficult, as the project grows with the time.