Package mainservlets

Source Code of mainservlets.runTimePrefApp

package mainservlets;

import java.io.IOException;

import javax.servlet.ServletContext;
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 timeprefapp.testSubject;

/**
* Servlet implementation class runTimePrefApp
*/
@WebServlet("/runTimePrefApp")
public class runTimePrefApp extends HttpServlet {
  private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public runTimePrefApp() {
        // 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
   
    //  id (user's input)
    int id = Integer.parseInt(request.getParameter("id"));
    // number of rounds
    int maxRounds = Integer.parseInt(request.getParameter("mr"));
       
    // 
    ServletContext context = this.getServletContext();
    String CURRDIR = context.getRealPath("/WEB-INF/lib/runTimePrefApp.jar").split("WEB-INF")[0];
   
        // Clear the screen (PITA in JAVA)
        try {
            if ((System.getProperty( "os.name")).startsWith(" Window ")) {
                Runtime.getRuntime().exec("cls"); }
            else { Runtime.getRuntime().exec("clear"); }
        }catch(Exception e) {
          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }

        //  run testSubject class.
        testSubject subj = new testSubject(id, maxRounds, CURRDIR)
        subj.testThisSubject();
  }

  /**
   * @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);
  }

}
TOP

Related Classes of mainservlets.runTimePrefApp

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.