File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jsp - why need to specify these headings? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "jsp - why need to specify these headings?" Watch "jsp - why need to specify these headings?" New topic
Author

jsp - why need to specify these headings?

tangara goh
Ranch Hand

Joined: Dec 27, 2009
Posts: 125
Hi,

I am trying to use session to track the login user.

What happened is that I found something useful in the internet that I can emulate from.

However, I don't understand why they put these 2 lines above the jsp page.

Hope to get some advice. tks.

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

<jsp:useBean class = "Beans.User" id = "userid" scope = "application"></jsp:useBean>
<jsp:setProperty name = "userid" property = "*"/>

Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9023


This is the JSP page directive (more info).
The first line creates an instance of Bean.User class (if one doesn't exist in application scope, more info about jsp:useBean can be found here) and then the second line sets any properties of the User class to matching request parameters (mode info about jsp:setProperty can be found here). So if the request had a parameter named age, and the User class has setAge method, then the setAge method is called with the value of the age request parameter...


Javaranch SCJP FAQ | SCWCD Links
tangara goh
Ranch Hand

Joined: Dec 27, 2009
Posts: 125
Thanks. I believe that programmer must have created beans for the different parameters using getter and setter right?

What if I'm not using beans but using only html form to get the user name, address blah blah, do I still need to put int that 2 lines?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
Right now it looks to me like there's *way* too much going on in the JSP--the only reasons to import sql are bad ones.

It's also a little weird that there's a user bean in application scope and not session scope.
 
 
subject: jsp - why need to specify these headings?
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com