Im new to java an oop programming and I'm having trouble figuring out how to process this method in a .jsp file. Sorry about the limited info so Im going to elaborate cause I'm still stuck. I have a LoginServlet that gets input from a html file.
LoginServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
loginInfo.setUsername(username);
loginInfo.setPassword(password);
request.setAttribute("login", loginInfo);
ServletContext context = getServletContext();
RequestDispatcher dispatch = context.getRequestDispatcher("/Accounts.jsp");
dispatch.forward(request, response);
}
Then I have JavaBean.java with accessors/mutators for password and username and the JavaBean also has this method
JavaBean - get/set methods for password & username and this method getAccounts()
public Account[] getAccounts() {
return new Account[] {
new Account(3001, "Checking", 29.96f , 2912.96f),
new Account(4001, "Savings", 500.00f, 10030.50f),
new Account(6001, "IRA", 1000.25f, 43456.83f)
};
}
Ok, now finally I have the Account.java that only the JavaBean.java has access to so I need to create an instance using getAccounts() then access the getter and setters within Account.java. Last I'm going to include the Accounts.jsp code
Accounts.jsp
<jsp:useBean id="login" class="edu.pcc.cis234j.assign04b.LoginBean" scope="request">
<jsp:setProperty property="*" name="login"/>
</jsp:useBean>
<h1>Welcome, <jsp:getProperty property="userName" name="login"/> How's your day going?</h1>
<% Account[] a = login.getAccounts(); %>
So how would I process this so I can display the new account info. without having access to Account.java and having this method within JavaBean.java returning an array of Account.java instances.
hard-codedarray? What compiler error did you get?reference / import Account[] class fileto access it's data and further processing.