reset password
Author Message
hhuang30
Posts: 40
Posted 10:09 Jan 17, 2014 |

1. An app is put in the directory "username/WEB-INF/class/subfolder" on the cs3 server,  why it only shows "cs3.calstatela.edu/username/appmap"  in the url instead of "cs3.calstatela.edu/username/WEB-INF/class/subfolder/appmap"

2. When will the app be initialized? As long as they are uploaded into the server ? Assume the app have "loadOnStartup" element

Thank you
 

Last edited by hhuang30 at 11:06 Jan 17, 2014.
cysun
Posts: 2935
Posted 10:56 Jan 17, 2014 |

1. The answer to this question has several parts.

(a) This is the difference between "static web" and "dynamic web" (remember what we discussed in the first class). In static web a request is mapped to a file on the disk of the server; in dynamic web the request is mapped to a program running on the server (i.e. it no longer matters where on the disk the program code resides).

(b) A web application usually consists of both programs, e.g. servlets, and static resources, e.g. HTML pages, images, and so on. The way application servers typically work is that when a request comes in, it first tries to find a program that can process the request. For example, with servlets it will look for a servlet whose URL mapping in @WebServlet matches the request URL. If the server cannot find a program for the request, it will look for a static resource that match the request URL, and this part works mostly the same as in static web. For example, if there's no servlet handling the request http://localhost:8080/myapp/img/icon.png, Tomcat will look for an icon.png file under the WebContent/img folder.

(c) WEB-INF is a special folder that cannot be accessed remotely through a browser. This is important because you don't want somebody to steal your code by simply typing http://<host>/<app>/WEB-INF/classes/YourCode.class in their browser. Java application servers will always return 404 error to any request to /WEB-INF/.... This also makes WEB-INF a good folder to use if you want to "hide" something from the direct access of your users.

2. A web application may have more than one servlet, so there's a difference between when the "app" is loaded and when a servlet in the web app is started.

An web app is loaded when it's deployed to the application server. There are several way to deploy a web app to Tomcat (see Tomcat Web App Deployment), but unfortunately most of the deployment methods require admin/manager access to the server, and we cannot give that to every student in the class. This is why to deploy to CS3 you have to copy over your files one by one. Tomcat will load (or reload) your application when it detects that the web.xml file is changed (not necessarily in content - just changing the file timestamp is enough), and this is why you should always upload web.xml last, or do a "touch" command on web.xml after you upload all the other files.

A web app being loaded doesn't mean the servlets in the web app are started. In fact, by default servlets are not started until the first request to that servlet comes in. With loadOnStartup though, the servlet will be started (and its init() method called) when the application is deployed.

Last edited by cysun at 14:08 Jan 17, 2014.
hhuang30
Posts: 40
Posted 17:20 Jan 17, 2014 |

That makes great sence, helps a lot. 

Thank you so much