The following is to help jumpstart you with Project 3, if you are a bit stumped. You'll have to convert the following either into a servlet or to be used with a servlet. Using the code from the "WhoIs w/ java.net" link above you can have code similar to:
package com.jamesoravec;
import java.net.*;
import java.io.*;
public class whois {
public final static int port = 43;
public final static String hostname = "whois.internic.net";
public whois(String input) {
Socket theSocket;
DataInputStream theWhoisStream;
PrintStream ps;
try {
theSocket = new Socket(hostname, port, true);
ps = new PrintStream(theSocket.getOutputStream());
ps.print(input + " ");
ps.print("\r\n");
theWhoisStream = new DataInputStream(theSocket.getInputStream());
String s;
while ((s = theWhoisStream.readLine()) != null) {
System.out.println(s);
}
}
catch (IOException e) {
System.err.println(e);
}
}
public static void main(String[] args) {
Socket theSocket;
DataInputStream theWhoisStream;
PrintStream ps;
try {
theSocket = new Socket(hostname, port, true);
ps = new PrintStream(theSocket.getOutputStream());
for (int i = 0; i < args.length; i++) ps.print(args[i] + " ");
ps.print("\r\n");
theWhoisStream = new DataInputStream(theSocket.getInputStream());
String s;
while ((s = theWhoisStream.readLine()) != null) {
System.out.println(s);
}
}
catch (IOException e) {
System.err.println(e);
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import com.jamesoravec.*;
/**
*
* @author joravec
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
whois myWhoIs = new whois("jamesoravec.com");
}
}
Lab exercises:
14. Permutations of letters (e.g. abc, acb, bac, bca, cab, cba)
15. Code a sorting network, using permuations to verify correctness of sorting network, for all possible inputs.
16. Create visual sorting network output for a 3 sorting netework.
17. Create a sorting network that will sort 6 items and verify it for all 6 input (a,b,c,d,e,f) permuations. (Hint: 6 inputs means 6! possible input strings, or 6*5*4*3*2*1 = 720 possible input strings).
18. Java power example. Write a simple program that has a jsp request calculations from a servlet which in turns requests inforamtion from a normal java class. Display the output to the web broswer.
*19. For advanced students. Can you write a program that will make sorting networks, test them for correctness, and log the results?
- If the sorting network is correct, then log statistical information about them, such as number of compares to sort everything, and the order of comparisions. You'll also want to have a systematic way of saving your progress automatically, and resuming your progress through writing to files (or database). It would be preferred to write to a db, so that you can have a jsp for viewing results while the other program runs in the background.
- Is there a way to verify your solution is optimal? If so, can you write explain it to me in one page or less?
- Can and does your solution use threads to its advantage?
- How did you implement your solution? Did you have have to run the program as a standard java program and use servlets/jsp for viewing the results? Or were you able to do it all through servlets/jsp?
*20. For advanced students. Write a program that gives a visual of fractals.
*21. For advanced students. Write a jsp page that which connects to a db, and perform a simple XSS on the db using javascript alert(). Make a copy of the jsp page and rewrite it to protect against the XSS attack.
*22. For advanced students. Write a program that will take a URL, and traverse its links 3 deep and return a list of all emails it comes across. On your webpages, what can you do to make it more difficult, for people who write such programs, to get your email address?
Extra Credit: Challenge yourself with some ACM programming problems. Program the answers in java, submit them to the site and then redo them as jsp or as a servlet. Submit your both your java code and jsp/servlet code to me once the website approves your answer.
When on the website you'll want to click on "browse problems" on the left, then "problem set volumes." You'll have to create an account, submit your code and verify that it is correct through their system. Once you have successfully coded problem(s), send me an email with the code which references the website description and problem number and have your class name and your name documented in the code as well. Some problems are easier than others, which can be judged by me on the solving percent shown by the UVA system. The harder the problem, the more extra credit you'll receive. If you kmnow Java then you can submit the answers to the website that way.