Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp - why need to specify these headings?  RSS feed

 
tangara goh
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
tangara goh
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!