У меня есть проект JPA в затмение. Я хочу, чтобы, когда профессор Cli c на "Connexion", через сервлет, он проверил, находятся ли электронная почта и пароль в базе данных. Дерево проекта:
- marksManagementEAR
- marksManagementEJB
- clientPackage
- modelePackage
- Student. java
- Presentation. java
- Professor. java
- MarksManagementManager. java -> function который я буду использовать позже
- MarksManagerRemote. java
- marksManagementEJBClient
- marksManagementWeb
- srcPackage
- controlPackage
- EjbLocator. java
- StudentListServlet. java -> doGet ();
- CnxVerificationServlet. java -> doPost ( );
Теперь у меня есть этот EjbLocator. java:
public class EjbLocator {
private static Context ctx;
private static EjbLocator instance = new EjbLocator();
private EjbLocator() {}
public static EjbLocator getLocator() {
return instance;
}
private <T> T getEjb(Class<T> ejbClass, String beanName) {
try {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
final String appName = "MarksMnagementEAR";
final String moduleName = "MarksManagementEJB";
return (T) context.lookup("java:global/" + appName + "/" + moduleName + "/" + beanName + "!" +
ejbClass.getName());
} catch (NamingException e) {
return null;
}
}
public MarksManagementRemote getMarksManagementManager() {
return getEjb(MarksManagementRemote.class, "MarksManagement");
}
}
Эта функция внутри MarksManagementManager. java:
@Override
public boolean connexionVerification(String email, String password) {
Query query = em.createQuery("SELECT email,password FROM professor pt WHERE pt.email= :email AND pt.password= :password");
query.setParameter(email, 1);
query.setParameter(password, 2);
Professor professor = (Professor)query.getSingleResult();
if(professor == null) {
System.out.println("THE PROFESSOR DOES EXIST");
return true;
} else {
System.out.println("THE PROFESSOR DOES NOT EXIST OR WRONG EMAIL / PASSWORD");
return false;
}
}
И внутри ConnexionVerificationServlet. java:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Professor professor = new Professor();
professor.setEmail(request.getParameter("professor.email"));
prof_tuteur.setPassword(request.getParameter("professor.password"));
MarksManagementRemote marksManagementRemote = EjbLocator.getLocator().getMarksManagementRemote ();
boolean successfulConnexion= marksManagementRemote.connexionVerification(?,?);
if(successfulConnexion== true) {
//????
}
else {
//????
}
}
Часть JavaClient. java:
JButton btn_connexion = new JButton("Connexion");
btn_connexion.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//When the professor clic on the button, the verification goes on
}
});
И картинка клиента внизу сообщения. Я использую сервер wildfly
и wamp
. Моя база данных создана с файлами, которые я положил в MarksManagementEJB
.
У меня есть несколько проблем.
1. In ConnexionVerificationServlet.java, I should put the content of the `JTextField` and
`JPasswordField` at the end of this line `boolean successfulConnexion=marksManagementRemote.connexionVerification(?,?);` ?
2. The connexion to the database path is: `Clic on connexion` -> `ConnexionServlet.java` -> `MarksManagementManager.java (ejb session stateless)` -> `database`. Am I right ?
3. My configuration is the good one (the folder, files and so on) ?
Сердечно