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 Setting page var in scriptlets function? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Setting page var in scriptlets function?" Watch "Setting page var in scriptlets function?" New topic
Author

Setting page var in scriptlets function?

Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
Hi,

I cant make it to run we service function in JSP because I cant get request variable from the same page:

I have login.jsp page:


And when I run the code I get an error:


So, how can I set variable in scriptlet function?

Maybe with pageContext? But how?

Regardes,
Marko
[ November 06, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

Firstly, why are you mixing JSTL and scriplets in the same page? Messy. I'd recommend using one or the other.

Secondly, using a JSP for authentication in this manner is pretty old-fashioned. I suggest you bone up on the use of servlet filters.

And finally:

String username = (String) request.getParameter(username);

Carefully look at that line. What is it you are expecting to pass to the getParameter method? The contents of the variable username that you haven't set yet?
[ November 06, 2006: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
Hi Bear,
why are you mixing JSTL and scriplets in the same page? Messy. I'd recommend using one or the other.

I must do so, because I am calling web service operation, and Netbeans do generation of scriptlet code by him self.

Secondly, using a JSP for authentication in this manner is pretty old-fashioned

I am not doing authentication, this is only simplified example, so I could show my problem.

And I have modify code (two e in usernamee):


and I still get an exeption:
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
[javac] C:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-modules\MailAgregator\org\apache\jsp\noviKorisnik_jsp.java:170: cannot find symbol
[javac] symbol : variable usernamee
[javac] location: class org.apache.jsp.login_jsp
[javac] String username = (String) request.getParameter(usernamee);
[javac]

regardes,
Marko
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1004
JSTL and scriptlet code don't share the same variable space.

${username} is approximately equivalent to <%= pageContext.findAttribute("username") %>

<c:set var="username" value="${param.username}" scope="request" />
is translated into java as
request.setAttribute("username", request.getParameter("username"));
The JSTL code has no interaction at all with scriptlet variables declared on the page.
That is why the recommendation is to use one or the other.

I would recommend you try


IMO this should probably be written into a servlet in any case which does the login and then uses the request dispatcher to forward to a result page, or back to the login page if the login attempt failed.

Cheers,
evnafets
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Setting page var in scriptlets function?
 
Similar Threads
why i am getting this error while my file has no such code
Internal Error while Validating username and password
how to call Jsp in servlet
generated servlet of jsp file
login page