Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts

21 April 2011

How to implement counter for foreach in jsp ?

Solution for jsp 2.0

in for foreach tag you need add varStatus with name and use name.index  in place where you need counter variable:

<c:forEach var="chicks" varStatus="counter" items="${form.girlimageslist}">
  Girl no. ${counter.index} picture path : ${chicks},
</c:forEach>

15 April 2011

List of all tags in shiro jsp tag library

List valid for Apache Shiro 1.1.0
(It is copied and pasted from apache shiro website.)
  1. <shiro:guest/> - Displays body content only if the current Subject IS NOT known to the system, either because they have not logged in or they have no corresponding 'RememberMe' identity. It is logically opposite to the 'user' tag.
  2. <shiro:user/> - Displays body content only if the current Subject has a known identity, either from a previous login or from 'RememberMe' services. Note that this is semantically different from the 'authenticated' tag, which is more restrictive. It is logically opposite to the 'guest' tag.
  3. <shiro:principal/> - Displays the user's principal or a property of the user's principal.
  4. <shiro:hasPermission/> - Displays body content only if the current Subject (user) 'has' (implies) the specified permission (i.e the user has the specified ability).
  5. <shiro:lacksPermission/> - Displays body content only if the current Subject (user) does NOT have (not imply) the specified permission (i.e. the user lacks the specified ability)
  6. <shiro:hasRole/> - Displays body content only if the current user has the specified role.
  7. <shiro:lacksRole/> - Displays body content only if the current user does NOT have the specified role (i.e. they explicitly lack the specified role)
  8. <shiro:hasAnyRoles/> - Displays body content only if the current user has one of the specified roles from a comma-separated list of role names
  9. <shiro:authenticated/> - Displays body content only if the current user has successfully authenticated during their current session. It is more restrictive than the 'user' tag. It is logically opposite to the 'notAuthenticated' tag.
  10. <shiro:notAuthenticated/> - Displays body content only if the current user has NOT succesfully authenticated during their current session. It is logically opposite to the 'authenticated' tag.

(Source: http://shiro.apache.org/jsp-tag-library.html )

How to declare shiro tag library in jsp?

You simply need copy and paste below line:
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> 

30 March 2011

How to comment in jsp

To start single/multi line comment, insert this:
<%--

 To finish comment insert this:
 --%>

Single line comment example:
<%-- i love smell of napalm in the morning --%>

multi line comment example:

<%--
- When is summer in UK?
- When rain is warm .
--%>

23 March 2011

How to add js file to jsp file and how to solve problems related to adding javascript file to jsp file

So you using creating jsp file and you want add js file and you think it simple because jsp is like html so ....

Peace of cake.
And you add this line:
<script language="JavaScript" type="text/javascript" src="./js/amazingscript.js"></script>

and Firebug and see 404 file not found

and you thinking what a minute... but file is there! What are you talking about ?
So you looking for solution on Internet and you see that you have 2 solutions:

1) You should put
in head (or between </head> and <body> it is wrong place to put it but it will work usually)
<script language="JavaScript" type="text/javascript" src="./js/amazingscript.js"></script>

2)You should put
<jsp:include page="./js/amazingscript.js"></jsp:include>

In many cases both solution doesn't work or weird things happen.
Why ?

In case 1) you will see error that file is not found
because: either this file really DOESN'T EXIST (because of misspell , remember about case sensitive !) or you put file in area which in place which is not accessible (like inside WEB-INF folder ).

In case 2) you will see your source code as plain text in browser instead of result of execution javascript
because jsp is executed on SERVER SIDE (server) and js is executed on CLIENT SIDE (user's browser)!

What else can go wrong?
It usually problem with path  (more about path i will  write in next post )

How to include JavaScript file in jsp file that will be work?

1)First put JavaScript in place where can be accessed!(For example :everything stored in WEB-INF folder will not work!!if you using spring framework).

2)Use script tag <script language="JavaScript" type="text/javascript" src="./js/amazingscript.js"></script>

ps. be careful as well with path (more about path