Skip to content
Open

WK9 #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions webApp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<display-name>Archetype Created Web Application</display-name>

<servlet>
<servlet-name>stockSearchServlet</servlet-name>
<servlet-class>com.origamisoftware.teach.advanced.webApp.stockSearchServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>stockSearchServlet</servlet-name>
<url-pattern>/webApp/stockSearchServlet/*</url-pattern>
</servlet-mapping>

</web-app>
33 changes: 33 additions & 0 deletions webApp/stockQuote.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<jsp:useBean id="StockQuery" class="com.origamisoftware.teach.advanced.model.StockQuery" scope="request"/>
<jsp:useBean id="Interval" class="com.origamisoftware.teach.advanced.util.Interval" scope="request"/>
<jsp:setProperty name="StockQuery" property="*"/>
<jsp:setProperty name="Interval" property="*"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Stock Quote Request</title>
</head>
<body>
<h2>
Please enter StockQuery information: <br>
</h2>
<P></P>
<form name="stockQuote" action="stockQuoteResults.jsp" method="post">
Stock Symbol : <input type="text" name="symbol"
value='<%= StockQuery.getSymbol() == null ? "" : StockQuery.getSymbol() %>'><br>
Stock Date From : <input type="text" name="from"
value='<%= StockQuery.getFrom()== null ? "" : StockQuery.getFrom() %>'><br>
Stock Date Until : <input type="text" name="until"
value='<%= StockQuery.getUntil()== null ? "" : StockQuery.getUntil() %>'><br>
Stock Date Interval : <input type="text" name="interval"
value='<%= Interval.getMinutes() != 0 ? "" : Interval.getMinutes() %>'><br>
<input type="SUBMIT" value="OK">
<input type="HIDDEN" name="submit" value="true">
</form>

</body>
</html>
21 changes: 21 additions & 0 deletions webApp/stockQuoteResults.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:useBean id="StockQuery" class="com.origamisoftware.teach.advanced.model.StockQuery" scope="request"/>
<jsp:useBean id="Interval" class="com.origamisoftware.teach.advanced.util.Interval" scope="request"/>
<jsp:setProperty name="StockQuery" property="*"/>
<jsp:setProperty name="Interval" property="*"/>
<html>
<head>
<title>Stock Quote Query Results</title>
</head>
<body>
<h1>Your Stock Quote</h1>

Symbol: <%= StockQuery.getSymbol() %>
Date From: <%= StockQuery.getFrom() %>
Date Until: <%= StockQuery.getUntil() %>
Interval in Minutes: <%= Interval.getMinutes() %>

Thank you!
</body>
</html>
52 changes: 52 additions & 0 deletions webApp/stockSearchServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.origamisoftware.teach.advanced.webApp;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
* Example servlet from the apache tomcat distribution
*/
public class stockSearchServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Request Information Example</title>");
out.println("</head>");
out.println("<body>");
out.println("<h3>Request Information Example</h3>");
out.println("Method: " + request.getMethod());
out.println("Request URI: " + request.getRequestURI());
out.println("Protocol: " + request.getProtocol());
out.println("PathInfo: " + request.getPathInfo());
out.println("Remote Address: " + request.getRemoteAddr());
out.println("</body>");
out.println("</html>");
}

/**
* We are going to perform the same operations for POST requests
* as for GET methods, so this method just sends the request to
* the doGet method.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doGet(request, response);

ServletContext servletContext = getServletContext();
RequestDispatcher dispatcher = servletContext.getRequestDispatcher("/stockQueryResults.jsp");
dispatcher.forward(request, response);

}

}