Я пытаюсь получить некоторые значения из таблицы, используя источник данных в структурах, но это дает исключение:
тип Отчет об исключении
сообщение
описание Сервер обнаружил внутреннюю ошибку(), который не позволил ему выполнить этот запрос.
исключение
javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.NullPointerException
login.LoginAction.execute(LoginAction.java:31)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note Примечание Полная трассировка стека основной причины доступна в журналах Apache Tomcat / 6.0.26.
и мой файл struts-config.xml содержит свойство соединения с источниками данных:
<form-beans>
<form-bean name="LoginForm" type="login.LoginForm"/>
<form-bean name="dynaActionForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="fname" type="java.lang.String"/>
<form-property name="lname" type="java.lang.String"/>
</form-bean>
</form-beans>
<data-sources>
<data-source key="dataSource" type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<set-property property="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<set-property property="url" value="jdbc:sqlserver://192.168.1.169:1433;databaseName=localDB"/>
<set-property property="username" value="sa"/>
<set-property property="password" value="pass"/>
</data-source>
</data-sources>
<global-exceptions></global-exceptions>
<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>
<action-mappings>
<action name="LoginForm" path="/login" scope="request" type="login.LoginAction" validate="false">
<forward name="failure" path="/login.jsp"/>
<forward name="success" path="/WEB-INF/success.jsp"/>
</action>
<action name="dynaActionForm" path="/dyna" scope="request" type="DaynaAction.dynaActionClass" validate="false">
<forward name="filure" path="/index.jsp"/>
<forward name="success" path="/WEB-INF/JSP/SuccessDyna.jsp"/>
</action>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="com/myapp/struts/ApplicationResource"/>
<!-- ========================= Tiles plugin ===============================-->
<!--
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
module).
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation
Paths found in Tiles definitions are relative to the main context.
-->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
и мой класс действий:
package login;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.*;
import javax.sql.DataSource;
public class LoginAction extends org.apache.struts.action.Action {
/* forward name="success" path="" */
private static final String SUCCESS = "success";
private final static String FAILURE = "failure";
private ResultSet rs;
private PreparedStatement ps;
private Connection conn;
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm formBean = (LoginForm) form;
String fname = formBean.getName();
String lname = formBean.getEmail();
if ((fname == null) || lname == null) {
ArrayList al = new ArrayList();
DataSource ds = (DataSource) servlet.getServletContext().getAttribute("");
conn = ds.getConnection();
String query = "select * from login";
ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
int i = 1;
while (rs.next()) {
al.add(rs.getString(i));
al.add(rs.getString(i + 1));
i++;
}
request.setAttribute("value", al);
formBean.setError();
return mapping.findForward(FAILURE);
}
return mapping.findForward(SUCCESS);
}
}
Пожалуйста, помогите любомузапустить вышеуказанную программу .....
С уважением, Mouli V