package joseflueth; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import joseflueth.net.sourceforge.matex.*; /* * Created on 24.12.2003 * * Copyright 2003, by Josef Lüth * */ /** * @author Josef Lüth * * @version 1.0 * * Calcuate terms the user entered. * This servlet uses Matex Modul (mateSoft.com) * to calculate terms. * */ public class MatexCalcSE extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); //get the term the user entered String term = req.getParameter("term"); //calculate the term String result; try { result = Parser.parse(term).eval(); } catch (CalculateException e) { //if there is an error while calculating result = "Error: " + e.getMessage() + ""; } //if the user entered nothing catch (NullPointerException e) { //if there is an error while calculating result = "Keine Eingabe"; } //write the html page out.println(""); out.println(""); out.println("Matex Calulator- Result"); out.println(""); out.println(""); out.println( ""); out.println(""); out.println(" "); out.println( " "); out.println( " "); out.println( " "); out.println("
"); //show the result out.println( "

Term: " + term + "" + "  Result: " + result + "

"); out.println("

 

Enter a new term

 

Calculated by Matex (opensource, matexSoft.com)

"); out.println( "

Matex Calculator 1.0 Server Edition

"); out.println(""); } }