• Post Reply Bookmark Topic Watch Topic
  • New Topic

Action is not firing from the jsp page  RSS feed

 
rinki gose
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi readers,

i tried to load a combo box using the htmlptions collection during the page load in the jsp page from a database. i prepared form bean,action,configured the xml files, kept the necessary tag libraries. i am able to get the values from the database into the arraylist that i am using if i make the code containing the database operation as a dao and test it. but unfortunately if i make it in the same action class by calling it, i couldnt fire the action itself

please see the code below and make me know where lies the error

jsp page:

<%@ page import="com.personalinfo.beans.*" %>
<%@ page import="com.personalinfo.form.*" %>
<bean:define id="genderListOptions" name="PersonalInformationForm" property="genderListOptions" type="java.util.ArrayList"/>
.
<html:form action="/PersonalInformationAction">
.
.
<html:select property="selGender" styleClass="txtwidh">
<htmlptions collection="genderListOptions" property="value" labelProperty="label"/>
</html:select>
.
</html:form>


model class:

package com.personalinfo.model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import com.personalinfo.form.PersonalInformationForm;

public class PersonalInformationModel
{
/*public static void main(String args[])
{
PersonalInformationModel personalInformationModel=new PersonalInformationModel();
ArrayList arr=personalInformationModel.fillGender();
}*/
public ArrayList fillGender()
{
ArrayList<String> listOptions=new ArrayList();
boolean valid = false;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
//PersonalInformationForm personalinformationForm = null;
try
{
PersonalInformationForm personalInformationForm=new PersonalInformationForm();
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/personalinformation", "", "");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT gender FROM person");
while(rs.next())
{
String gen=rs.getString("gender");
listOptions.add(gen);
System.out.println(gen);
}
personalInformationForm.setGenderListOptions(listOptions);



}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
try { if (rs != null) rs.close(); } catch (SQLException e) {};
try { if (stmt != null) stmt.close(); } catch (SQLException e) {};
try { if (con != null) con.close(); } catch (SQLException e) {};
}
return listOptions;
}
}

action class:

public class PersonalInformationAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
System.out.println("hii action");
PersonalInformationForm personalInformationForm = (PersonalInformationForm)form;
PersonalInformationModel perInformationModel=new PersonalInformationModel();
ArrayList arr=perInformationModel.fillGender();

return mapping.findForward("success");
}
}

form class:

public class PersonalInformationForm extends ActionForm {

private ArrayList genderListOptions = new ArrayList();
private String selGender;

public void setSelGender(String string)
{
this.selGender = string;
}
public String getSelGender()
{
return this.selGender;
}

public ArrayList getGenderListOptions() {
return genderListOptions;
}
public void setGenderListOptions(ArrayList genderListOptions) {
this.genderListOptions = genderListOptions;
}

public void reset(ActionMapping mapping,HttpServletRequest request)
{
PersonalInformationModel personalInformationModel=new PersonalInformationModel();
ArrayList arr=personalInformationModel.fillGender();
request.setAttribute( "genderListOptions", arr);

}

struts-config.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<!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>
<form-beans>
<form-bean name="PersonalInformationForm" type="com.personalinfo.form.PersonalInformationForm"/>
</form-beans>
<action-mappings>
<action path="/PersonalInformationAction" type="com.personalinfo.action.PersonalInformationAction" name="PersonalInformationForm" scope="session">
<forward name="failure" path="/jsp/personal.jsp"/>
<forward name="success" path="/jsp/x.jsp"/>
</action>
</action-mappings>
</struts-config>

web.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<!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 >
<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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/jsp/personal.jsp</welcome-file>
</welcome-file-list>


<!-- Struts Tag Library Descriptor -->
<taglib>
<taglib-uri>struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>c.tld</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>


</web-app>


please let me know the solution ASAP.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things to help you make the most of JavaRanch as a resource:

First of all, ease up. Phrases like "please let me know the solution ASAP" are pushy and just tick people off. Please read this for more information.

Also, Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information. You can go back and change your post to add code tags by clicking the .

And lastly, Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this. This post has been moved to a more appropriate forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!