According to thread MVC above, I create web.xml like this
<servlet>
<servlet-name>addServlet</servlet-name>
<servlet-class>servlet.AddServlet</servlet-class>
<init-param>
<param-name>dbURL</param-name>
<param-value>jdbc:odbc:database</param-value>
</init-param>
<init-param>
<param-name>dbUserName</param-name>
<param-value>username</param-value>
</init-param>
<init-param>
<param-name>dbPassword</param-name>
<param-value>password</param-value>
</init-param>
<init-param>
<param-name>JdbcDriver</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>servlet.loginServlet</servlet-class>
<init-param>
<param-name>dbURL</param-name>
<param-value>jdbc:odbc:database</param-value>
</init-param>
<init-param>
<param-name>dbUserName</param-name>
<param-value>username</param-value>
</init-param>
<init-param>
<param-name>dbPassword</param-name>
<param-value>password</param-value>
</init-param>
<init-param>
<param-name>JdbcDriver</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>registerServlet</servlet-name>
<servlet-class>servlet.registerServlet</servlet-class>
<init-param>
<param-name>dbURL</param-name>
<param-value>jdbc:odbc:database</param-value>
</init-param>
<init-param>
<param-name>dbUserName</param-name>
<param-value>username</param-value>
</init-param>
<init-param>
<param-name>dbPassword</param-name>
<param-value>password</param-value>
</init-param>
<init-param>
<param-name>JdbcDriver</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</init-param>
</servlet>
myServlet.java
...
public void init(ServletConfig config) throws ServletException {
super.init(config);
dm = new dataManager();
dm.setDbURL(config.getInitParameter("dbURL"));
dm.setDbUserName(config.getInitParameter("dbUserName"));
dm.setDbPassword(config.getInitParameter("dbPassword"));
try {
Class.forName(config.getInitParameter("JdbcDriver"));
}
catch (Exception ex) {
System.out.println("Initialize connector string");
ex.printStackTrace();
}
}
...
Is there any other way to minimize the code in web.xml, so I don't have to add init parameter in all servlet.
Btw, how can I get the id of Array, so I can take an action for it.
For example, if I delete the title number 1, it will be delete title number 1, and if I wan to edit title number 2, it will edit title number 2.
Better illustration is in the attachment.
Thanks a lot