|
Creating a Java Servlet!
Description:
The purpose of this assignment is to write a servlet that does authentication of a username and password. As part of the authentication you must create session variables to identify you as an individual and that can be checked by other servlets (actually JSP pages) that you will create for assignment #7.
Create an xhtml form that allows a user to enter a username and password. Include a login button. You must include client side validation before the username and password are submitted to the server. The login button should submit the form and pass the username and password to your servlet which should then check a file on the server to verify the username and password. The password file must contain at least 3 different users and their corresponding passwords. If the password is invalid the servlet should return an error message informing the user of the invalid password and return to the login page. If the password is valid, then create a session variable containing the user's name and then display a web page indicating the login was successful. (In assignment #7 we will replace this web page with a JSP page).
Your "action" attribute should look as follows:
<form action = "http://157.201.194.254:8080/cs313/servlet/s13.yourNetId.assign06>
Setting up your development environment:
1. Your java class name must be assign06 (assign06.java) (Remember your class name must match your filename) a. You must place the servlet program in the directory I created for you in the following directory: home/ercanbracks/tomcat55/tomcat/webapps/cs313/WEB-INF/classes/s13/yourNetId Note: To simplify changing to this deep directory structure. Create a linux symbolic link in your home directory. It can be done as follows: ln -s /home/ercanbracks/tomcat55/tomcat/webapps/cs313/WEB-INF/classes/s13/yourNetId symlinkName cd symLinkName // changes to the directory you specified in your symbolic link
b. set the permissions on your java source file to rwx for owner only: (e.g. chmod 700 myfile.java) c. you must include a package statement in the beginning for your java source file as follows: package s13.yourNetId;
2. To compile your servlet program: javac6 -classpath ../../j2ee.jar assign06.java
3. You will use the tomcat application server running on Jordan (157.201.194.254) to run your servlets
4. To test your servlet - from the browser enter: http://157.201.194.254/~yourNetId/assign06.html. or execute it directly by: http://157.201.194.254:8080/cs313/servlet/s13.yourNetId.assign06
5. Note: The path for your data file is relative from where the Tomcat Server was started, which is in the tomcat55 directory. If you use a filename "without a path" it will be created in the /home/ercanbracks/tomcat55 directory. Therefore to create the file in your personal directory you would need a full Linux file path. If you want to create the file in your personal servlet directory use a path like shown below:
new File ("tomcat/webapps/cs313/WEB-INF/classes/s13/yourNetId/yourFile.dat"); 6. Once your servlet is finished, you will need to "submit" your java file so I can grade your java servlet Your .java and .class files need to remain in WEB-INF/classes. However, I need a copy of your java source file submitted to me, so I can view it. You can run submit from this directory and submit your java source file. Be sure you have the proper heading comment block in your java source file so the submit will work properly. /*************************** * Program: * Assignment 06, Java Servlet * Brother Ercanbrack, cs313 ***************************/
:Note: Tomcat will check your servlet (java class file) and if it has been modified within the last 15 to 30 seconds it will reload your servlet. So with about 20 seconds after compiling your servlet, you should be able to see the changes through the browser.
|
|
|
|
|