• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting page var in scriptlets function?

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic