I am using QuickFixJ with SpringBoot to publish market price data to Bloomberg. When publishing prices, everything is working well. However, I cannot see any prices published on Bloomberg when I hit ALLQ.
Event log files :
8=FIXT.1.1^A9=60^A35=0^A34=617^A49=ARHGPROD^A52=20211110-16:16:44.472^A56=BBGPROD^A10=223^A
8=FIXT.1.1^A9=60^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=603^A52=20211110-16:16:58.566^A10=227^A
8=FIXT.1.1^A9=60^A35=0^A34=618^A49=ARHGPROD^A52=20211110-16:17:14.472^A56=BBGPROD^A10=222^A
8=FIXT.1.1^A9=60^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=604^A52=20211110-16:17:28.573^A10=224^A
8=FIXT.1.1^A9=60^A35=0^A34=619^A49=ARHGPROD^A52=20211110-16:17:44.472^A56=BBGPROD^A10=226^A
8=FIXT.1.1^A9=60^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=605^A52=20211110-16:17:58.576^A10=231^A
8=FIXT.1.1^A9=89^A35=A^A34=1^A49=ARHGPROD^A52=20211110-16:18:45.788^A56=BBGPROD^A98=0^A108=30^A141=Y^A789=1^A1137=9^A10=059^A
8=FIXT.1.1^A9=83^A35=A^A49=BBGPROD^A56=ARHGPROD^A34=1^A52=20211110-16:18:46.082^A98=0^A108=30^A141=Y^A1137=9^A10=018^A
8=FIXT.1.1^A9=161^A35=X^A34=2^A49=ARHGPROD^A52=20211110-16:18:49.492^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=192^A
8=FIXT.1.1^A9=161^A35=X^A34=3^A49=ARHGPROD^A52=20211110-16:18:49.496^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=197^A
8=FIXT.1.1^A9=160^A35=X^A34=4^A49=ARHGPROD^A52=20211110-16:18:49.499^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2343341074^A22=4^A270=98.39^A279=0^A269=1^A48=XS2343341074^A22=4^A270=99.39^A10=128^A
8=FIXT.1.1^A9=160^A35=X^A34=5^A49=ARHGPROD^A52=20211110-16:18:49.500^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2343341074^A22=4^A270=98.39^A279=0^A269=1^A48=XS2343341074^A22=4^A270=99.39^A10=112^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=2^A52=20211110-16:19:16.585^A10=129^A
8=FIXT.1.1^A9=58^A35=0^A34=6^A49=ARHGPROD^A52=20211110-16:19:19.609^A56=BBGPROD^A10=133^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=3^A52=20211110-16:19:46.587^A10=135^A
8=FIXT.1.1^A9=58^A35=0^A34=7^A49=ARHGPROD^A52=20211110-16:19:49.609^A56=BBGPROD^A10=137^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=4^A52=20211110-16:20:16.595^A10=124^A
8=FIXT.1.1^A9=58^A35=0^A34=8^A49=ARHGPROD^A52=20211110-16:20:19.609^A56=BBGPROD^A10=127^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=5^A52=20211110-16:20:46.597^A10=130^A
8=FIXT.1.1^A9=58^A35=0^A34=9^A49=ARHGPROD^A52=20211110-16:20:49.609^A56=BBGPROD^A10=131^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=6^A52=20211110-16:21:16.603^A10=117^A
8=FIXT.1.1^A9=59^A35=0^A34=10^A49=ARHGPROD^A52=20211110-16:21:19.609^A56=BBGPROD^A10=170^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=7^A52=20211110-16:21:46.610^A10=119^A
8=FIXT.1.1^A9=59^A35=0^A34=11^A49=ARHGPROD^A52=20211110-16:21:49.609^A56=BBGPROD^A10=174^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=8^A52=20211110-16:22:16.616^A10=124^A
8=FIXT.1.1^A9=59^A35=0^A34=12^A49=ARHGPROD^A52=20211110-16:22:19.609^A56=BBGPROD^A10=173^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=9^A52=20211110-16:22:46.621^A10=124^A
8=FIXT.1.1^A9=59^A35=0^A34=13^A49=ARHGPROD^A52=20211110-16:22:49.609^A56=BBGPROD^A10=177^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=10^A52=20211110-16:23:16.626^A10=168^A
8=FIXT.1.1^A9=59^A35=0^A34=14^A49=ARHGPROD^A52=20211110-16:23:19.609^A56=BBGPROD^A10=176^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=11^A52=20211110-16:23:46.632^A10=169^A
8=FIXT.1.1^A9=59^A35=0^A34=15^A49=ARHGPROD^A52=20211110-16:23:49.609^A56=BBGPROD^A10=180^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=12^A52=20211110-16:24:16.636^A10=172^A
8=FIXT.1.1^A9=59^A35=0^A34=16^A49=ARHGPROD^A52=20211110-16:24:19.609^A56=BBGPROD^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=13^A52=20211110-16:24:46.643^A10=174^A
8=FIXT.1.1^A9=59^A35=0^A34=17^A49=ARHGPROD^A52=20211110-16:24:49.609^A56=BBGPROD^A10=183^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=14^A52=20211110-16:25:16.647^A10=177^A
8=FIXT.1.1^A9=59^A35=0^A34=18^A49=ARHGPROD^A52=20211110-16:25:19.609^A56=BBGPROD^A10=182^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=15^A52=20211110-16:25:46.654^A10=179^A
Message log files :
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=30^A52=20211110-16:33:16.726^A10=172^A
8=FIXT.1.1^A9=59^A35=0^A34=34^A49=ARHGPROD^A52=20211110-16:33:19.609^A56=BBGPROD^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=31^A52=20211110-16:33:46.731^A10=172^A
8=FIXT.1.1^A9=59^A35=0^A34=35^A49=ARHGPROD^A52=20211110-16:33:49.609^A56=BBGPROD^A10=183^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=32^A52=20211110-16:34:16.733^A10=173^A
8=FIXT.1.1^A9=59^A35=0^A34=36^A49=ARHGPROD^A52=20211110-16:34:19.609^A56=BBGPROD^A10=182^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=33^A52=20211110-16:34:46.739^A10=183^A
8=FIXT.1.1^A9=59^A35=0^A34=37^A49=ARHGPROD^A52=20211110-16:34:49.609^A56=BBGPROD^A10=186^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=34^A52=20211110-16:35:16.742^A10=176^A
8=FIXT.1.1^A9=59^A35=0^A34=38^A49=ARHGPROD^A52=20211110-16:35:19.609^A56=BBGPROD^A10=185^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=35^A52=20211110-16:35:46.750^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A34=39^A49=ARHGPROD^A52=20211110-16:35:49.609^A56=BBGPROD^A10=189^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=36^A52=20211110-16:36:16.757^A10=185^A
8=FIXT.1.1^A9=59^A35=0^A34=40^A49=ARHGPROD^A52=20211110-16:36:19.609^A56=BBGPROD^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=37^A52=20211110-16:36:46.763^A10=186^A
8=FIXT.1.1^A9=162^A35=X^A34=41^A49=ARHGPROD^A52=20211110-16:36:49.235^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=239^A
8=FIXT.1.1^A9=162^A35=X^A34=42^A49=ARHGPROD^A52=20211110-16:36:49.236^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=241^A
My Java code :
/**
* Classe responsable de la publication des prix sur Bloomberg
* */
public class BloombergPricePublisher {
Logger logger = LoggerFactory.getLogger(BloombergPricePublisher.class);
/**
* Constructeur de BloombergPricePublisher
* */
public BloombergPricePublisher(){
super();
}
/**
* Méthode de publication d'un prix sur Bloomberg
* */
public void publish(MarketPrice marketPrice) {
MarketDataIncrementalRefresh marketDataIncrementalRefresh = createMarketDataIncrementalRefresh(marketPrice);
try{
for (SessionID sessionID : ValuationApplication.threadedSocketInitiator.getSessions()){
Boolean sent = Session.lookupSession(sessionID).send(marketDataIncrementalRefresh);
logger.info("Prix publié sur Bloomberg : " + marketDataIncrementalRefresh.toString().replace('\001', '|'));
logger.info("Confirmation de réception : " + sent);
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* Méthode de création d'un nouveau prix pour le publier sur Bloomberg
* #param marketPrice
* */
public MarketDataIncrementalRefresh createMarketDataIncrementalRefresh(MarketPrice marketPrice) {
quickfix.fix50sp2.MarketDataIncrementalRefresh message = new MarketDataIncrementalRefresh();
quickfix.fix50sp2.MarketDataIncrementalRefresh.NoMDEntries group = new MarketDataIncrementalRefresh.NoMDEntries();
message.getHeader().setString(1022, "****");
/**
* FIX tags :
* 8: BeginString
* 9: BodyLength
* 10: CheckSum
* 22: IDSource
* 34: MsgSeqNum
* 35: MsgType
* 49: SenderCompID
* 52: SendingTime
* 56: TargetCompID
* 268: NoMDEntries
* 269: MDEntryType
* 270: MDEntryPx
* 279: MDUpdateAction (0 = New, 1 = Change, 2 = Delete)
* */
/**
* Ajout prix Bid au message
* */
group.setString(48, marketPrice.getISIN());
group.setString(22, "4");
group.setString(279, "0");
group.setString(269, "0");
group.setString(270, marketPrice.getBid_kech().toString());
message.addGroup(group);
/**
* Ajout prix Ask au message
* */
group.setString(48, marketPrice.getISIN());
group.setString(22, "4");
group.setString(279, "0");
group.setString(269, "1");
group.setString(270, marketPrice.getAsk_kech().toString());
message.addGroup(group);
return message;
}
}
I cannot see what I'm doing wrong as my parameter send is set to true after the Publish method is called. Can anyone help me with this issue? Many thanks in advance !
Just changed publication to CUSIP instead of ISIN
Hello Im trying to remove an elemento from a HashSet that have an entity created by me that is called "Product" this is the code:
Set listaItemsTrans = this.getTransaction().getTransactionItems();
HashSet listaIteratorI = new HashSet();
listaIteratorI.addAll(listaItemsTrans);
Iterator itemSet = listaIteratorI.iterator();
while (itemSet.hasNext())
{
Product prodBif = (Product) itemSet.next();
logger.debug("Prod bif = " + prodBif.getIdProduct() + " = " + "Prod search = " + prodSearch.getIdProduct());
if (prodBif.getIdProduct().compareTo(prodSearch.getIdProduct()) == 0)
{
logger.debug("El Producto ha sido encontrado");
try
{
logger.debug("ProdBif " + prodBif);
logger.debug("Lista de productos 3 " + this.getTransaction().getTransactionItems());
boolean isRemoved;
isRemoved = this.getTransaction().getTransactionItems().remove(prodBif);
logger.debug("isRemoved? " + isRemoved);
}
catch (Exception e)
{
e.printStackTrace();
}
logger.debug("Lista de productos 4" + this.getTransaction().getTransactionItems());
prodBif = prodSearch;
this.getTransaction().getTransactionItems().add(prodBif);
logger.debug("Lista de productos 5" + this.getTransaction().getTransactionItems());
isOkey = true;
}
}
The product is the same i already check that but im gonna put the product equal:
Product Bif: Product [idProduct=1546405266442777, transaction=Transaction [idTransaction=1546405253162777, transaction=077700514, transactionDate=2019-01-02 10:01:06, session=Session [idSession=1546405226194777, session=00130777000000011111, cashier=com.lds.exito.darchitecture.domainmodel.entities.Cashier#d8241df3, store=Store [idStore=1546405226193777, store=0013, description=EXTITO GRAN VIA M001120], terminal=777, sessionDate=2019-01-02 10:00:26], sequenceNumber=0514, ], pluVariety=000000213690, salePrice=9900, description=NEVERA NO FROST 39, details={CashierID=0000011111, mensaje=Certificado valido, TransactionID=0514, AuthorizationBus=CommunicationHttpBodyAuthBus, ValidationResponseRevertionStatus=com.lds.exito.soa.status.validation.IvaDifResponseStatusValidation, portPrimary=, hostPrimary=http://wsredverde.datagestion.co/ws/?a=2&certificado=3&identificacion=8276946&codigo=13, contentType=application/json, StoreID=0013, PREFIX_AUTH_END_identificacion==8276946, OriginalTerminalID=777, nroIdentificacion=8276946, uri=, AuthorizationClassName=FinalAuthorizationHttp, plu=000000213690, PREFIX_AUTH_END_certificado==3, TerminalID=777, fechaHora=2019-01-02T10:01:06, nroCertificado=3, OriginalTransactionID=0514}, extras={transaction_record=IvaDif/IvaDif-99-129,,, voucher_list=IvaDif/FooterRecarga,}, authorizationType=ParametersConfig [idParameter=2, descriptionGroup=Tipos de Autorizacion, idGroup=TPAUT, descriptionParameter=Autorizacion al Final de la Transaccion, parameterValue=ENDTR], authorizationStatus=ParametersConfig [idParameter=3, descriptionGroup=Estado de la Autorizacion, idGroup=STAUT, descriptionParameter=Pendiente, parameterValue=PNDNG], reverseType=ParametersConfig [idParameter=7, descriptionGroup=Tipos de Reverso, idGroup=TPREV, descriptionParameter=No Aplica, parameterValue=NOAPP], reverseStatus=ParametersConfig [idParameter=8, descriptionGroup=Estado del Reverso, idGroup=STREV, descriptionParameter=No Aplica, parameterValue=NOAPP], anulationType=ParametersConfig [idParameter=11, descriptionGroup=Tipos de Anulacion, idGroup=TPANU, descriptionParameter=Aplica, parameterValue=APPLY], anulationStatus=ParametersConfig [idParameter=13, descriptionGroup=Estado del Anulacion, idGroup=STANU, descriptionParameter=No Aplica, parameterValue=NOAPP], productType=ParametersConfig [idParameter=16, descriptionGroup=Tipos de Producto, idGroup=TPPDT, descriptionParameter=Item, parameterValue=ITEM], quantity=1, ]
Product in the HashSet: Product [idProduct=1546405266442777, transaction=Transaction [idTransaction=1546405253162777, transaction=077700514, transactionDate=2019-01-02 10:01:06, session=Session [idSession=1546405226194777, session=00130777000000011111, cashier=com.lds.exito.darchitecture.domainmodel.entities.Cashier#d8241df3, store=Store [idStore=1546405226193777, store=0013, description=EXTITO GRAN VIA M001120], terminal=777, sessionDate=2019-01-02 10:00:26], sequenceNumber=0514, ], pluVariety=000000213690, salePrice=9900, description=NEVERA NO FROST 39, details={CashierID=0000011111, mensaje=Certificado valido, TransactionID=0514, AuthorizationBus=CommunicationHttpBodyAuthBus, ValidationResponseRevertionStatus=com.lds.exito.soa.status.validation.IvaDifResponseStatusValidation, portPrimary=, hostPrimary=http://wsredverde.datagestion.co/ws/?a=2&certificado=3&identificacion=8276946&codigo=13, contentType=application/json, StoreID=0013, PREFIX_AUTH_END_identificacion==8276946, OriginalTerminalID=777, nroIdentificacion=8276946, uri=, AuthorizationClassName=FinalAuthorizationHttp, plu=000000213690, PREFIX_AUTH_END_certificado==3, TerminalID=777, fechaHora=2019-01-02T10:01:06, nroCertificado=3, OriginalTransactionID=0514}, extras={transaction_record=IvaDif/IvaDif-99-129,,, voucher_list=IvaDif/FooterRecarga,}, authorizationType=ParametersConfig [idParameter=2, descriptionGroup=Tipos de Autorizacion, idGroup=TPAUT, descriptionParameter=Autorizacion al Final de la Transaccion, parameterValue=ENDTR], authorizationStatus=ParametersConfig [idParameter=3, descriptionGroup=Estado de la Autorizacion, idGroup=STAUT, descriptionParameter=Pendiente, parameterValue=PNDNG], reverseType=ParametersConfig [idParameter=7, descriptionGroup=Tipos de Reverso, idGroup=TPREV, descriptionParameter=No Aplica, parameterValue=NOAPP], reverseStatus=ParametersConfig [idParameter=8, descriptionGroup=Estado del Reverso, idGroup=STREV, descriptionParameter=No Aplica, parameterValue=NOAPP], anulationType=ParametersConfig [idParameter=11, descriptionGroup=Tipos de Anulacion, idGroup=TPANU, descriptionParameter=Aplica, parameterValue=APPLY], anulationStatus=ParametersConfig [idParameter=13, descriptionGroup=Estado del Anulacion, idGroup=STANU, descriptionParameter=No Aplica, parameterValue=NOAPP], productType=ParametersConfig [idParameter=16, descriptionGroup=Tipos de Producto, idGroup=TPPDT, descriptionParameter=Item, parameterValue=ITEM], quantity=1, ]
And i dont know why that is happening, something that i miss?
Note 1: when i try to do the same thing with another product that code works
Note 2: Im using java 1.4 by restrictions in the hardware
When i am running the jsp page drops me this error , any suggestion in order to fix it , (i know jsp with java its not good)...
type Exception report
message An exception occurred processing JSP page
/assets/jsp/create-dest-code.jsp at line 31
description The server encountered an internal error that prevented it
from fulfilling this request.
exception org.apache.jasper.JasperException: An exception occurred
processing JSP page /assets/jsp/create-dest-code.jsp at line 31
28: if(id > -1) 29: { 30: int insert_ch; 31: for(int
i=0;i
insert_ch=myStatement.executeUpdate("INSERT INTO Dest_has_Categories
(Dest_idDest,Categories_idCategories) VALUES
('"+id+"','"+cat[i]+"')"); 34: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause java.lang.NullPointerException
org.apache.jsp.assets.jsp.create_002ddest_002dcode_jsp._jspService(create_002ddest_002dcode_jsp.java:136)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache
Tomcat/8.0.33 logs.
my code :
<%
String id8=request.getParameter("id8"); //Country field
String id9=request.getParameter("id9"); //City field
String id10=request.getParameter("id10"); //URL field
int id = -1;
Class.forName("com.mysql.jdbc.Driver");
String myDatabase = "jdbc:mysql://localhost:3306/project_app?user=root&password=1234";
Connection myConnection = DriverManager.getConnection(myDatabase);
Statement myStatement = myConnection.createStatement();
String sqlInsert = "INSERT INTO dest(Country,City,URL) VALUES ('"+id8+"', '"+id9+"','"+id10+"')";
myStatement.executeUpdate(sqlInsert);
ResultSet rs = myStatement.executeQuery("SELECT idDest FROM dest WHERE Country='"+id8+"' AND City='"+id9+"' AND URL='"+id10+"'" );
while (rs.next()) {
id=rs.getInt(1);
}
String cat[]=request.getParameterValues("dest1");
if(id > -1)
{
int insert_ch;
for(int i=0;i<cat.length;i++)
{
insert_ch=myStatement.executeUpdate("INSERT INTO Dest_has_Categories (Dest_idDest,Categories_idCategories) VALUES ('"+id+"','"+cat[i]+"')");
}
}
myStatement.close();
myConnection.close(); %>
<h1 style="color:blue;">Successful Registration </h1>
I assume that once you know what is the line #31, you will be able to fix your NPE thanks to many other questions of this type so let's focus on how to find the line #31 in your case.
According to your stacktrace you are using Tomcat 8, so the source code of your jsp file /assets/jsp/create-dest-code.jsp is in $TOMCAT_HOME/work/Catalina/localhost/assets/org/apache/jsp/jsp/create-dest-code_jsp.java, from here check the line #31 and you will know how to fix it.
Actually you have already the answer here:
28: if(id > -1) 29: { 30: int insert_ch; 31: for(int i=0;i
insert_ch=myStatement.executeUpdate("INSERT INTO Dest_has_Categories
(Dest_idDest,Categories_idCategories) VALUES
('"+id+"','"+cat[i]+"')"); 34: }
It seems that your variable cat is null which probably means that you have no value for the parameter dest1.
Are you sure you connection string is valid? In the example here There is more details in the connection string that is missing in your code (like database name) :
Connection con = null;
try {
con = DriverManager.getConnection(
"jdbc:sqlserver://localhost\\SQLEXPRESS;"
+ "user=sa;password=HerongY#ng;"
+ "database=AdventureWorks2014");
source
I've done my fair share of research and from what I've seen, I have everything correct. I'm trying to call a Java class in my JSP file. Every time I run it, I get the following error:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 25 in the jsp file: /3680-HW4-Taylor-Jacob/HTML/main.jsp
DateAssistant.formatDate cannot be resolved to a type
22: out.println("Welcome, " + request.getParameter("usrname") + "!");
23:
24: if (timezone.equalsIgnoreCase("United States")){
25: out.write("You logged in on: " + new DateAssistant.formatDate(gc, timezone) + "");
26:
27: }
28: out.write("Browse Movies Catalog");
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
I have the Class file in the correct place (WEB-INF/classes/wu/andy/DateAssistant.class), and I've imported correctly from what I've seen. Here is my JSP source code:
<%# page import="java.util.GregorianCalendar, wu.andy.*" %>
<%
String interest = request.getParameter("interest");
String password = request.getParameter("password");
GregorianCalendar gc = new GregorianCalendar();
int tz = 0;
String timezone = request.getParameter("country");
if(password.equals("JTaylor")){
if(interest.equals("music")){
response.sendRedirect("music.html");
}
else if(interest.equals("games")){
response.sendRedirect("games.html");
}
else if(interest.equals("movies")){
out.write("<html>");
out.write("<head/>");
out.write("<body>");
out.write("<h1 style='color:green'>Movies Galore :: User Main Page</h1>");
out.println("Welcome, " + request.getParameter("usrname") + "!");
if (timezone.equalsIgnoreCase("United States")){
out.write("<p>You logged in on: " + new DateAssistant.formatDate(gc, timezone) + "</p><br/><br/>");
}
out.write("<a href='movies.html'>Browse Movies Catalog</a>");
}
} else{
response.sendRedirect("login.html");
}
%>
I know my code is not "good practice" but this is how my professor wants it.
Any help would be appreciated!
Looks like you forgot to import DateAssistant class in jsp header.
<%# page import="java.util.GregorianCalendar, wu.andy.*, XXXXX.DateAssistant" %>
Your JSP line:
out.write("<p>You logged in on: " + new DateAssistant.formatDate(gc, timezone) + "</p><br/><br/>");
Uses the new keyword next to DateAssistant.formatDate(). Unless this is a public inner class I think this is a static method in which case you should drop the new
what was i doing wrong ??
I am running Apache tomcat 7 as a service in win 7
my jsp code [...\webapps\test\index.jsp ]
<jsp:useBean id="Counter" scope="session" class="aaa.Counter" />
<html>
<title>sfcsv</title>
<%
try{
int x = Counter.read_count(),z = Counter.get_id();
if(x%2==0)
out.println(x + " = even");
else
out.println(x + " = odd");
out.println(z);
}catch(Exception e){
out.println(e);
}
%>
</html>
the java code [..\webapps\test\WEB-INF\classes\aaa\Counter.java ]
package aaa;
public class Counter {
private int count;
private static int instance_counter;
private final int id;
public Counter(){
instance_counter ++;
id = instance_counter;
count = 0;
}
public int read_count(){
return count++;
}
public int get_id(){
return id;
}
}
expected output :
24 = even 1
output that I was getting :
24 = even
or
HTTP Status 500 - Unable to compile class for JSP: An error occurred at line: 8 in the jsp file: /index.jsp The method get_id() is undefined for the type Counter 5: 6: <% 7: try{ 8: int x = Counter.read_count(),z = Counter.get_id(); 9: if(x%2==0) 10: out.println(x + " = even"); 11: else Stacktrace:
type Exception report
message Unable to compile class for JSP: An error occurred at line: 8 in the jsp file: /index.jsp The method get_id() is undefined for the type Counter 5: 6: <% 7: try{ 8: int x = Counter.read_count(),z = Counter.get_id(); 9: if(x%2==0) 10: out.println(x + " = even"); 11: else Stacktrace:
description The server encountered an internal error (Unable to compile class for JSP: An error occurred at line: 8 in the jsp file: /index.jsp The method get_id() is undefined for the type Counter 5: 6: <% 7: try{ 8: int x = Counter.read_count(),z = Counter.get_id(); 9: if(x%2==0) 10: out.println(x + " = even"); 11: else Stacktrace:) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /index.jsp
The method get_id() is undefined for the type Counter
5:
6: <%
7: try{
8: int x = Counter.read_count(),z = Counter.get_id();
9: if(x%2==0)
10: out.println(x + " = even");
11: else
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.
Apache Tomcat/7.0.29
EDIT: On restarting the computer the problem vanished
You already solved your problem but here are the appropriate options to get all your classes and JSP files to be reloaded or recompiled which might help in understanding what was going on in your case:
Refreshing Java classes - Be sure to recompile your classes after applying changes to them. Also see the reloadable option for you web application context (default is false).
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected.
Refreshing JSP files - Please see the Tomcat Jasper docs for details on the development variable (defaults to true so I guess this is its value in your case) and the modificationTestInterval variable (defaults to 4 seconds) with which you may set the interval in which JSP files are checked for changes and compiled if necessary. Both are usually set in $CATALINA_BASE/conf/web.xml.
Is Jasper used in development mode? If true, the frequency at which JSPs are checked for modification may be specified via the modificationTestInterval parameter.true or false, default true.
I think its not problem with your code.I think your IDE is not building your project correctly
ie .class file is not generated properly( or not generated). so try to compile this file manually and place generated .class file to appropriate folder of your project and then build and restart your server.Check on build its building new .JAR file or not