Boa noite,
Estou tentando fazer a persistência de dados com o Postgrees do Full Calendar com Jquery, mas dá o seguinte erro:
GRAVE: Servlet [action] in web application [/JSPCalendar02] threw load() exception
java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1032)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:971)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5075)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
Servlet:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class getCal_Data_Servlet extends HttpServlet {
private final String DB_DRIVER = "org.postgresql.Driver";
private final String DB_CONNECTION = "jdbc:postgresql://localhost:5432/CALTEST?autoReconnect=true";
private final String DB_USER = "postgres";
private final String DB_PASSWORD = "123";
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
StringBuilder sb = new StringBuilder();
boolean enableDatabase = false; //Change to false in case you want to hard code the values
try {
if(enableDatabase)
{
Class.forName(DB_DRIVER);
connection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
String username = request.getParameter("username");
String sql = "SELECT "
+ "evtid,evtcreatorid,evtstartdate,evtenddate,evtdescription,evtbackgroundcolor, evtforegroundcolor "
+ "FROM calevents WHERE evtcreatorid=?";
ps = connection.prepareStatement(sql);
ps.setString(1,username);
rs = ps.executeQuery();
while(rs.next()) {
sb.append("Event ID:").append(rs.getString("evtid")).append(";");
sb.append("Created By:").append(rs.getString("evtcreatorid")).append(";");
sb.append("Event Start Date:").append(rs.getString("evtstartdate")).append(";");
sb.append("Event End Date:").append(rs.getString("evtenddate")).append(";");
sb.append("Event Description:").append(rs.getString("evtdescription")).append(";");
sb.append("BackgroundColor:").append(rs.getString("evtbackgroundcolor")).append(";");
sb.append("ForegroundColor:").append(rs.getString("evtforegroundcolor"));
sb.append("|");
}
connection.commit();
}
else
{
String evtid = "1";
String evtcreatorid = "Marcel Domingues";
String evtstartdate = "2019-08-17 12:00:00";
String evtenddate = "2019-08-17 16:00:00";
String evtdescription = "Hi this is a test event created by Me";
String evtbackgroundcolor = "#000000";
String evtforegroundcolor = "#ffffff";
out.println("Event ID:" + evtid + ";Created By:" + evtcreatorid + ";Event Start Date:" + evtstartdate + ";" +
"Event End Date:" + evtenddate + ";" + "Event Description:"+ evtdescription + ";" +
"BackgroundColor:" + evtbackgroundcolor + ";ForegroundColor:"+ evtforegroundcolor + "|");
evtid = "2";
evtcreatorid = "Marcel Motta";
evtstartdate = "2019-08-18 12:00:00";
evtenddate = "2019-08-18 16:00:00";
evtdescription = "Nothing fancy in this event. Only background and foreground colors have been changed";
evtbackgroundcolor = "#9E9E9E";
evtforegroundcolor = "#FFFFFF";
out.println("Event ID:" + evtid + ";Created By:" + evtcreatorid + ";Event Start Date:" + evtstartdate + ";" +
"Event End Date:" + evtenddate + ";" + "Event Description:"+ evtdescription + ";" +
"BackgroundColor:" + evtbackgroundcolor + ";ForegroundColor:"+ evtforegroundcolor + "|");
evtid = "3";
evtcreatorid = "Marcel Developer";
evtstartdate = "2019-08-19 12:00:00";
evtenddate = "2019-08-19 16:00:00";
evtdescription = "Go start your coding now!!!!!!!!";
evtbackgroundcolor = "#6699FF";
evtforegroundcolor = "#1A0000";
out.println("Event ID:" + evtid + ";Created By:" + evtcreatorid + ";Event Start Date:" + evtstartdate + ";" +
"Event End Date:" + evtenddate + ";" + "Event Description:"+ evtdescription + ";" +
"BackgroundColor:" + evtbackgroundcolor + ";ForegroundColor:"+ evtforegroundcolor + "|");
}
} catch (Exception ex) {
out.println("Error ->" + ex.getMessage());
} finally {
out.close();
if(ps != null)
ps.close();
if(connection != null)
connection.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(getCal_Data_Servlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(getCal_Data_Servlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Servlet
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class storeCal_Data_Servlet extends HttpServlet {
private final String DB_DRIVER = "org.postgresql.Driver";
private final String DB_CONNECTION = "jdbc:postgresql://localhost:5432/CALTEST?autoReconnect=true";
private final String DB_USER = "postgres";
private final String DB_PASSWORD = "123";
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
String evId = "";
String username = request.getParameter("username");
String evtStartDate = request.getParameter("start_date");
String evtEndDate = request.getParameter("end_date");
String evtDescription = request.getParameter("desc");
String evtBackgroundColor = request.getParameter("bg_color");
String evtForegroundColor = request.getParameter("fg_color");
Class.forName(DB_DRIVER);
connection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
ps = connection.prepareStatement("SELECT MAX(evtid) + 1 FROM calevents");
rs = ps.executeQuery();
if(rs.next())
{
evId = rs.getString(1);
}
ps = connection.prepareStatement("INSERT INTO calevents (evid, evtcreatorid, evtstartdate, evtenddate," +
"evtdescription, evtbackgroundcolor, evtforegroundcolor) VALUES (?,?,?,?,?,?,?)");
ps.setString(1,evId);
ps.setString(2,username);
ps.setString(3,evtStartDate);
ps.setString(4,evtEndDate);
ps.setString(5,evtDescription);
ps.setString(6,evtBackgroundColor);
ps.setString(7,evtForegroundColor);
ps.executeUpdate();
connection.commit();
out.println("Record added with event id: " + evId);
} catch (Exception ex) {
out.println("Error ->" + ex.getMessage());
} finally {
out.close();
if(ps != null)
ps.close();
if(connection != null)
connection.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(storeCal_Data_Servlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(storeCal_Data_Servlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
FrontierCalendarEx.jsp
BD Postgresql:
CREATE TABLE public.calevents
(
evtid integer NOT NULL,
evtcreatorid character varying(255),
evtstartdate timestamp without time zone,
evtenddate timestamp without time zone,
evtdescription character varying(2000),
evtbackgroundcolor character varying(10),
evtforegroundcolor character varying(10),
CONSTRAINT id_calevents_pk PRIMARY KEY (evtid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.calevents
OWNER TO postgres;
Todas as libs adicionadas:
antlr-2.7.7.jar
commons-beanutils-1.9.3.jar
commons-chain-1.2.jar
commons-digester-2.1.jar
commons-lang-2.6.jar
commons-logging-1.2.jar
commons-validator-1.4.0.jar
javax.servlet-api-3.0.1.jar
jstl-1.2.jar
oro-2.0.8.jar
postgresql-9.1-901-1.jdbc4.jar
struts-taglib-1.3.10.jar
struts2-core-2.5.20.jar