Created
April 24, 2014 17:39
-
-
Save amirdt22/11263033 to your computer and use it in GitHub Desktop.
CT390 Lab3 Submission #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ct390; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.annotation.WebServlet; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import javax.servlet.http.HttpSession; | |
/** | |
* Servlet implementation class HelloName | |
*/ | |
@WebServlet("/HelloName") | |
public class HelloName extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
/** | |
* @see HttpServlet#HttpServlet() | |
*/ | |
public HelloName() { | |
super(); | |
// TODO Auto-generated constructor stub | |
} | |
/** | |
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) | |
*/ | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
if (request.getParameter("name") == null) | |
response.getWriter().println("Hello World"); | |
else | |
greet(request, response); | |
// TODO Auto-generated method stub | |
String username = request.getParameter("username"); | |
HttpSession session = request.getSession(); | |
session.setAttribute("name", username); | |
} | |
private void greet(HttpServletRequest request, HttpServletResponse response) | |
throws IOException { | |
response.getWriter().println("Hello " + request.getParameter("name")); | |
} | |
/** | |
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) | |
*/ | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
greet(request, response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overall a nice code, the author used generic variables that are easily understood and doPost and doGet are both well written out.
Two things that I noticed that would be a good addition are requests for the session and cookies. To improve your code you can make these additions for the session and cookies: