The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
Author

jsp - why need to specify these headings?

tangara goh
Ranch Hand

Joined: Dec 27, 2009
Messages: 52

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
Bartender

Joined: Aug 03, 2008
Messages: 6324


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...

SCJP 6.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links
tangara goh
Ranch Hand

Joined: Dec 27, 2009
Messages: 52

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
Bartender

Joined: Sep 29, 2008
Messages: 6740

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.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
The most intelligent Java IDE