• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting page var in scriptlets function?  RSS feed

 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!