Connecting to the database from JSP page

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Connecting to the database from JSP page

Postby marsoups » 10 Sep 2015, 01:33

Hi,

Does anyone know if it would be possible to connect to the database from Jetty using JSP page, by referring to zone settings somehow ?

We have Jetty acting as a load balancer and would like it if we can make quick connections to the database to check a parameter, is this possible ?


Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Connecting to the database from JSP page

Postby Lapo » 10 Sep 2015, 07:39

Yes, there should be no problem.
You should be able to obtain a reference to SmartFox via this line:

Code: Select all

SmartFox sfs = SmartFoxServer.getInstance();


From there you can access the Zone:

Code: Select all

Zone myZone = sfs.getZoneManager().getZoneByName("myZone");


and finally the DBManager object:

Code: Select all

IDBManager db = myZone.getDBManager();


hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Re: Connecting to the database from JSP page

Postby marsoups » 10 Sep 2015, 11:23

Fantastic! Thank you :)
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Re: Connecting to the database from JSP page

Postby marsoups » 15 Oct 2015, 05:55

How can the JSP load the SFS classes ?

Getting an error even with importing the relevant classes :

Code: Select all

<%@ page import="com.smartfoxserver.v2.SmartFoxServer,com.smartfoxserver.v2.entities.SFSZone,com.smartfoxserver.v2.db.SFSDBManager" %>

<%
SmartFox sfs = SmartFoxServer.getInstance();
   Zone myZone = sfs.getZoneManager().getZoneByName("myZone");
   IDBManager db = myZone.getDBManager();
%>


Caused by:

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6197: An error occurred at line: 5 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
SmartFox cannot be resolved to a type

PWC6197: An error occurred at line: 5 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
Zone cannot be resolved to a type

PWC6197: An error occurred at line: 5 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
IDBManager cannot be resolved to a type
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Re: Connecting to the database from JSP page

Postby marsoups » 15 Oct 2015, 06:28

Ok I figured out the problem - need to use SmartFoxServer, I don't think SmartFox exists as a class definition ?

This solved the issue:

Code: Select all

<%@ page import="com.smartfoxserver.v2.*,com.smartfoxserver.v2.entities.*,com.smartfoxserver.v2.db.*" %>
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Connecting to the database from JSP page

Postby Lapo » 15 Oct 2015, 08:13

No, there is no such class as SmartFox. The name is SmartFoxServer.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 53 guests