Question
Overview: The program will create a Servlet that will respond to HTML requests with text streams. The servlet will have locally instantiated Expert System object.
Overview: The program will create a Servlet that will respond to HTML requests with text streams. The servlet will have locally instantiated Expert System object. The website will allow a user to see results from the Expert System or add new data to the Expert System. Specifics: index.html Webpage that allows the user to select a link to go to the using page or a link to go to the training page. These buttons / links will call the servlet. The servlet will serve up either using.jsp (with appropriate data) or training.jsp. using.jsp Webpage that allows the user to query the Expert System using a drop down list of key words. Initially this page has no results, only the drop down list and a button. The button click will call the servlet. The servlet will serve up using.jsp with appropriate data. This page will also a button to go to the training page. training.jsp Webpage that allows the user to update the Expert System using two text fields. One is a key that may or may not already be in the Expert System. The other is a new value. The button click will call the servlet. The servlet will either add to an existing keys values (if the key already exists) or will add a new key / value pair. The servlet will serve up the training.jsp page. This page will also a button to go to the using page. DataServlet.java The servlet class that manages all of the requests and responses.
here is the code:
songdatabase:
package project2;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class SongDatabase
*/
@WebServlet("/SongDatabase")
public class SongDatabase extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public SongDatabase() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
String name = request.getParameter("name");
if(request.getParameter("indexButton")!=null)
{
String song = request.getParameter("textbox1");
response.getWriter().append("Your name is: "+name);
response.getWriter().append(" ");
String car = request.getParameter("cars");
response.getWriter().append("You would like a: "+car);
}
else if(request.getParameter("startUsing")!=null)
{
String label1="selectionList";
String label1Value = "
label1Value += "";
label1Value += "";
label1Value += "";
label1Value += "";
label1Value += "";
request.setAttribute(label1,label1Value);
RequestDispatcher rd=request.getRequestDispatcher("/using.jsp");
rd.forward(request,response);
}
// did this response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
index.html:
Produces: Partial Codeusing.jsp:
training.jsp:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started