Bonjour,
je viens de crée ma première page JSP qui consiste en un formulaire qui permet de se connecter a un serveur OpenErp mais j'ai quelque difficulté niveau connection .
Edit : J'ai réussi a corriger le problème .J'aurai une autre question , voila je me connecte a mon serveur OpenErp via deux page web de log :
- une ou j'introduit l'ip et le port du serveur qui va ensuite me retourner un vector avec la liste des DB présente sur le serveur .
-la deuxième page qui récupère la liste des DB dans une liste déroulante et un champ login et mdp .
J'ai voulu utiliser deux pages jsp pour réaliser cette manip, ma question est : est ce possible ?
(gros debutant en jsp et en servlet )
Voici le code de mes deux jsp :
Login.jsp(normalement le jsp qui contient la liste D et le login/mdp)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 <%@ page language ="java" import="java.net.MalformedURLException" import= "java.net.URL" import="java.util.Vector" import="java.util.logging.Level" import="java.util.logging.Logger" import="org.apache.xmlrpc.XmlRpcException" import="org.apache.xmlrpc.client.XmlRpcClient" import="org.apache.xmlrpc.client.XmlRpcClientConfigImpl"%> <html> <body bgcolor="white"> <form action="login.jsp" method="get"> <table> <tr> <td>Database</td><td><input type="text" name="t0" ></td> </tr> <tr> <td>login</td><td><input type="text" name="t1" ></td> </tr> <tr> <td>Password</td> <td><input type="password" name="t2"></td> </tr> <tr> <td></td> <td><input type="submit" name="b1" value="ok"> <input type="reset" name="b2" value="annuler"></td> </tr> </table> <% Vector<String> test = ; String db = request.getParameter("t0"); String user=request.getParameter("t1"); String pass=request.getParameter("t2"); int ids=-1; if (user != null){ Logger logger=null; XmlRpcClient xmlrpcLogin = new XmlRpcClient(); Object[] params=null; XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl(); xmlrpcConfigLogin.setEnabledForExtensions(true); try { xmlrpcConfigLogin.setServerURL(new URL("http", "10.10.210.75", 8069, "/xmlrpc/common")); } catch (MalformedURLException ex) { } xmlrpcLogin.setConfig(xmlrpcConfigLogin); try { params = new Object[] {db,user,pass}; Object id = xmlrpcLogin.execute("login", params); if (id instanceof Integer) ids =(Integer)id; }catch (XmlRpcException e) { logger.warning("XmlException Error while logging to OpenERP: "); ids=-2; } catch (Exception e) { logger.warning("Error while logging to OpenERP: "); ids= -3; } } %> <% if(ids>0){%> <jsp:forward page="loginSucces.jsp" /> <%}%> </form> </body> </html>
FindDatabase.jsp (va chercher la liste des DB):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 <%@ page language ="java" import="java.net.MalformedURLException" import= "java.net.URL" import="java.util.Vector" import="java.util.logging.Level" import="java.util.logging.Logger" import="org.apache.xmlrpc.XmlRpcException" import="org.apache.xmlrpc.client.XmlRpcClient" import="org.apache.xmlrpc.client.XmlRpcClientConfigImpl"%> <html> <body bgcolor="white"> <form action="login.jsp" method="post"> <table> <tr> <td>IP Serveur</td><td><input type="text" name="ipS" ></td> </tr> <tr> <td>Port</td><td><input type="text" name="ptS" ></td> </tr> <tr> <tr> <td></td> <td><input type="submit" name="b1" value="Ok"><input type="reset" name="b1" value="annuler"></td> </tr> </table> <% String ipServeur = request.getParameter("ipS"); String portS = request.getParameter("ptS"); if(ipServeur!=null){ int port = Integer.parseInt(portS); XmlRpcClient xmlrpcDb = new XmlRpcClient(); Logger logger=null; Vector<Object> params=null; Vector<String> res=null; XmlRpcClientConfigImpl xmlrpcConfigDb = new XmlRpcClientConfigImpl(); xmlrpcConfigDb.setEnabledForExtensions(true); try { xmlrpcConfigDb.setServerURL(new URL("http",ipServeur,port, "/xmlrpc/db")); } catch (MalformedURLException ex) { } xmlrpcDb.setConfig(xmlrpcConfigDb); //Retrieve databases params = new Vector<Object>(); Object result = null; try { result = xmlrpcDb.execute("list", params); } catch (XmlRpcException ex) { } Object[] a = (Object[]) result; res = new Vector<String>(); for (int i = 0; i < a.length; i++) { if (a[i] instanceof String) { res.addElement((String)a[i]); } } } //return res; %> </form> </body> </html>
Partager