I'm having some problems in creating sessions in JSP pages. I'm new to it so I need some advices.
<%@ page import="entity.*" %>
<%
HttpSession session=request.getSession(true);
String id = request.getParameter("idNo");
String fullName = request.getParameter("fullName");
String maritalStatus = request.getParameter("maritalStatus");
String height = request.getParameter("height");
String weight = request.getParameter("weight");
String gender = request.getParameter("gender");
String age = request.getParameter("age");
String dateOfBirth = request.getParameter("dateOfBirth");
String placeOfBirth = request.getParameter("placeOfBirth");
String idNo = request.getParameter("idNo");
String countryOfIssue = request.getParameter("countryOfIssue");
String nationality = request.getParameter("nationality");
String race = request.getParameter("race");
String homeNo = request.getParameter("homeNo");
String officeNo = request.getParameter("officeNo");
String mobileNo = request.getParameter("mobileNo");
String address = request.getParameter("address");
String postalCode = request.getParameter("postalCode");
String corrAddress = request.getParameter("corrAddress");
String corrPostalCode = request.getParameter("corrPostalCode");
String emailAddress = request.getParameter("emailAddress");
id = "P-" + id;
session.setAttribute("id", id);
%>
<%
String command1 = request.getParameter("command");
if ((command1 != null) && (command1.equals("insert")))
{
MainApplicant lifeinsured = new MainApplicant();
lifeinsured.setFullName(fullName);
lifeinsured.setMaritalStatus(maritalStatus);
lifeinsured.setHeight(height);
lifeinsured.setWeight(weight);
lifeinsured.setGender(gender);
lifeinsured.setAge(age);
lifeinsured.setDateOfBirth(dateOfBirth);
lifeinsured.setPlaceOfBirth(placeOfBirth);
lifeinsured.setIdNo(idNo);
lifeinsured.setCountryOfIssue(countryOfIssue);
lifeinsured.setNationality(nationality);
lifeinsured.setRace(race);
lifeinsured.setHomeNo(homeNo);
lifeinsured.setOfficeNo(officeNo);
lifeinsured.setMobileNo(mobileNo);
lifeinsured.setAddress(address);
lifeinsured.setPostalCode(postalCode);
lifeinsured.setCorrAddress(corrAddress);
lifeinsured.setCorrPostalCode(corrPostalCode);
lifeinsured.setEmailAddress(emailAddress);
lifeinsured.createMainApplicant();
response.sendRedirect("Step2App.jsp?command=new");
}
%>
I want to insert my ID into the database using session.setAttribute so that when I go to my next JSP page, I can retrieve the ID and use String id = (String)session.getAttribute("id"); to insert the same ID into another table.
But when I run my codes, everything works fine but the ID inserted will become null.
Can anyone help me? Thanks