1 Reply Latest reply on Apr 8, 2010 2:26 AM by Jean-Frederic Clere

    jsp, java servlet and drl file

    Johanna Voxy Apprentice

      Hi guys,

      I am trying to create a web page with a form, so when we click on submit, we are redirected to the result web page, but the content of this page will be generated according to the rules i created in my drl file. Does anyone knows the easiest way to do this? are they a way to call the drl file from the jsp file, or the servlet file?

       

      For now, i created a very simple form i put in my index.jsp file :

       

      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Insert title here</title>
      </head>
      <body>
          <form action="GreetingServlet" method="POST">
              First Name: <input type="text" name="firstName" size="20"><br>
              Surname: <input type="text" name="surname" size="20">
              <br><br>
              <input type="submit" value="Submit">
          </form>

      </body>
      </html>

      And a java servlet file

      package com.test1.servlet;

      import java.io.IOException;
      import java.io.PrintWriter;

      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      public class NameServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
          public NameServlet() {
              super();
          }       
          
            protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
             response.setContentType("text/html;charset=UTF-8");
              PrintWriter out = response.getWriter();
              String firstName = request.getParameter("firstName").toString();
              String surname = request.getParameter("surname").toString();

              out.println("<html>");
              out.println("<head>");
              out.println("<title>Servlet NameServlet</title>");
              out.println("</head>");
              out.println("<body>");
              out.println("<h1>Servlet NameServlet at " + request.getContextPath () + "</h1>");
              out.println("<p>Welcome " + firstName + " " + surname + "</p>");
              out.println("</body>");
              out.println("</html>");

              out.close();

          }                 
      }

       

      But i would like to add a drl rule's file as:

       

      rule "HeeloVoxy"

          dialect "mvel"

          when

              surname == "Voxy"

          then

              System.out.println( "Hi voxy, it works!");

       

      end

       

      so i could decide using the rules what page or what content display.

       

      Any idea?

      thanks for any answer