Bonjour !
J'ai une appli web (un simple formulaire login/password pour commencer) qui fonctionne tres bien sans DataSource.
Des lors que je déclare un DataSource dans struts-config.xml, la servlet d'action devient indispo (erreur 503 : La servlet action est actuellement indisponible) et ce, meme si je ne fais pas appel au DataSource dans ma classe d'Action.
Voici plusieurs bouts de code :
--- struts-config.xml ---
--- classe d'Action : LoginAction.java ---
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config> <!-- Sources de données --> <!-- Beans de formulaire --> <data-sources> <data-source key="MyDB" className="org.apache.struts.config.DataSourceConfig"> <set-property property="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <set-property property="url" value="jdbc:oracle:thin:@10.10.10.15:1521:DEV"/> <set-property property="username" value="planning"/> <set-property property="password" value="planning"/> </data-source> </data-sources> <form-beans> <form-bean name="loginForm" type="fr.ntv.nvgestiondemande.forms.LoginForm" /> <form-bean name="menuForm" type="fr.ntv.nvgestiondemande.forms.MenuForm" /> </form-beans> <!-- Exceptions globales --> <global-exceptions> </global-exceptions> <!-- Références aval globales --> <global-forwards> </global-forwards> <!-- Mappages d'action --> <action-mappings> <action name="loginForm" path="/login" type="fr.ntv.nvgestiondemande.actions.LoginAction"> <forward name="success" path=".LoginOk"></forward> <forward name="failure" path=".LoginKo"></forward> </action> <action name="menuForm" path="/search" type="fr.ntv.nvgestiondemande.actions.MenuAction"> <forward name="success" path=".SearchOk" /> <forward name="failure" path=".SearchKo" /> </action> </action-mappings> <!-- Controleur --> <controller> </controller> <!-- Ressources de message --> <message-resources parameter="fr.ntv.nvgestiondemande.resources.ApplicationResources"/> <plug-in className="org.apache.struts.tiles.TilesPlugin" > <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml, /WEB-INF/tiles-tests-defs.xml,/WEB-INF/tiles-tutorial-defs.xml, /WEB-INF/tiles-examples-defs.xml" /> <set-property property="moduleAware" value="true" /> <set-property property="(Nouvelle propriété)" value=""/> </plug-in> </struts-config>
--- web.xml ---
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116package fr.ntv.nvgestiondemande.actions; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Vector; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import fr.ntv.nvgestiondemande.forms.LoginForm; import fr.ntv.nvgestiondemande.bean.DemandeFactory; import org.apache.log4j.Logger; /** * @version 1.0 * @author */ public class LoginAction extends Action { private Logger logger = Logger.getLogger(getClass()); public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionErrors errors = new ActionErrors(); ActionForward forward = new ActionForward(); // return value LoginForm loginForm = (LoginForm) form; try { // do something here } catch (Exception e) { // Report the error using the appropriate name and ID. errors.add("name", new ActionError("id")); } // If a message is required, save the specified key(s) // into the request for use by the <struts:errors> tag. if (!errors.isEmpty()) { saveErrors(request, errors); } // Write logic determining how the user should be forwarded. String login = loginForm.getLogin(); String password = loginForm.getPassword(); System.out.println("---Début---"); System.out.println("login=" + login); System.out.println("password=" + password); if (login.equals("flo") && password.equals("flo")) { forward = mapping.findForward("success"); logger.debug("login ok"); } else { forward = mapping.findForward("failure"); logger.debug("login ko"); } // javax.sql.DataSource dataSource=null; // java.sql.Connection myConnection = null; // System.out.println("---Connection---"); // try { // System.out.println("---GetDataSource---"); // logger.debug("1"); // dataSource = getDataSource(request, "MyDB"); // // System.out.println("---GetConnection---"); // logger.debug("2"); // myConnection = dataSource.getConnection(); // // System.out.println("---CreateStatement---"); // logger.debug("3"); // Statement st = myConnection.createStatement(); // // String query = "SELECT COUNT(*) FROM USER"; // System.out.println("---ResultSet---"); // ResultSet rs = st.executeQuery(query); // System.out.println(rs); // // rs.close(); // st.close(); // myConnection.close(); // } catch (SQLException sqle) { // getServlet().log("Connection.process", sqle); // } // if (request.getSession().getServletContext().getAttribute("users") // == null) { // System.out.println("user non null"); // } System.out.println("---Fin---"); // Finish with return (forward); } }
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app id="WebApp"> <display-name>nv-gestion-demande</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>validate</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>chemin_log</param-name> <param-value>WEB-INF/conf/log4j.properties</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri> <taglib-location>/WEB-INF/struts-template.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/datetime-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-datetime.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/string-1.0.1</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-string.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/utility</taglib-uri> <taglib-location>/WEB-INF/lib/utility.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/mailer-1.1</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-mailer.jar</taglib-location> </taglib> <taglib> <taglib-uri>jspsql</taglib-uri> <taglib-location>/WEB-INF/lib/jspsql.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/application-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-application.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/page-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-page.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/request-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-request.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/response-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-response.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/session-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/taglibs-session.jar</taglib-location> </taglib> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/i18n-1.0</taglib-uri> <taglib-location>/WEB-INF/lib/i18n.jar</taglib-location> </taglib> </web-app>
Merci à tous
Partager