are we have to remember parameter name?

Hi there,

I just new to J2EE stuffs and I just getting more excited as well as frustated! LOL! Anyway I got question... At the moment, I am trying to use JSTL and I want to make a B2B web application... I already went through and I just wondering should we put all parameter name into enum class or we just remember it whenever wants to use it... Example

I got parameter in Login.jsp, there are "userId", "password" and after user press Login button in Login.jsp, it will direct to servlet which will get the parameter... so if I want to get it by using servletRequest.getParameter( "userId" ) and servletRequest.getParameter( "password" )

Ok now, this is the problem, remembering 2 parameters it is very easy... but how about 50 parameters? Any solution about this problem? Thanks very much!

[817 byte] By [-wizz-a] at [2007-11-26 16:31:06]
# 1
that is why there is javabeans it has the accessor and mutator methods so you won't have to memorize the names but reuse the mthods
jgalacambraa at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

[nobr]Hi jgalacambra,

firstly, thanks for your reply! Hmm JavaBeans... Yeah I am currently using it! But as far as I know although I use JB it is still need to remember the name for example...

JSTL with JB

JB CODE

private long id;

private String logonID;

private String password;

public void setId( long id )

{

this.id = id;

}

public long getId()

{

return id;

}

public void setLogonID( String logonID )

{

this.logonID = logonID;

}

public String getLogonID()

{

return logonID;

}

public void setPassword( String password )

{

this.password = password;

}

public String getPassword()

{

return password;

}

}

JSP CODE

<%@ page contentType="text/html;charset=windows-1252" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>

<title>user</title>

</head>

<body>

<c:set var="user" value="${sessionScope.user}" />

<c:if test="${!empty user}" >

Hi ${user.name},

<br></br>

<div align="right">

<form name="formLogout" action="service" method="post">

<input type="hidden" name="commandName" value="Common-logout" />

<input type="submit" name="btnLogout" value="Logout"/>

</form>

</div>

</c:if>

</body>

</html>

and in the servlet, I still need to remember user which is JB Person, and its method... it will be worse in the heavy project... or maybe can you give me example to use the JB very efficient just like what you thought? Thanks very much![/nobr]

-wizz-a at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
ummm i didn't see your point on remembering the name
jgalacambraa at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi jgalacambra,

Actually if you see my code on

<c:set var="user" value="${sessionScope.user}" />

I already have to remember the user session value... because of it is quite a bit crucial object, it may be frequently used in many pages like... Order Page, preference Page, and soon... So that in the Order page we have to also remember the "${sessionScope.user}" in order to retain the user logged in value... So that is the problem...

-wizz-a at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
that is a session object.. as long as the session is not expired it will be remembered throughout the session, it is not like a request, that navigating through pages it can be lost
jgalacambraa at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Hi jgalacambra,

LOL... If you dont mind... Can you look again about my problem? it seems that you have quite a bit misunderstanding about my question.. From my thread topic it is clearly stated that do we have to make some collection to put all parameter name? for example

class enum collectionParam

{

userid, password, name

}

[/code/

and use it in servlet like

[code]

servletRequest.getParameter( collectionParam.userid.toString() );

instead of

servletRequest.getParameter( "userid" );

LOL i hope that will make you more understand about what am i asking at... LOL! Thanks very much!

-wizz-a at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
hahaha.. but you have JB, then you will use String username = JavaBeans.getUserName();instead of:servletRequest.getParameter( "userid" );you dont, put it on a collection, because each page can have different forms and may use different JB's
jgalacambraa at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Hi jgalacambra,

Hahaha! Sorry my reply is wrong... Actually if my previous example not userid but

class enum collectionParam

{

user, shipCart

}

and use it in servlet like

servletRequest.getSession(true).getAttribute( collectionParam.user.toString() );

instead of

servletRequest.getSession(true).getAttribute( "user" );

Haha! Im sorry if I make you confused! LOL! Anyway how about that one?

-wizz-a at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

you can put the bean into session

session.setAttribute("Account",AccountBean);

if you want to get the value of the contents you can use this:

AccountBean accountBean = session.getAttribute("Account")!=null?(AccountBean)session.getAttribute("Account"):new AccountBean();

then you can get the paramters:

String username = accountBean.getUsername();

jgalacambraa at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

Hi Jgalacambra,

That right, but can you see it? You got "Account" which is mapped into AccountBean... so just assume... my web site is finished.... and it may contain a lot lot lot of mapping object.... Like "Account" bind to AccountBean, "ShipCart" bind to ShipBean, "Preference" bind to PreferenceBean and a lot of others.... didnt you noticed that once you want to use one of them in the session collection... you have to remember what is the key value? Example in Payment Page you want to pay all stock in your current cart... so you have to remember what is the key of ShipBean in your session collection.... Thanks very much!

-wizz-a at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

first step is why do you to remember that if you database.. of course all tnsactions you made must be stored in db and not database, you have to fetch what is in the db, in practice, only the user credentials, like user and user role were stored in session and not your whole transactions you made. You have to store it o otherwise you will have to update and update your session variables, what if your session has expired, do you think the transaction was stored?

jgalacambraa at 2007-7-8 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...