This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes How to use JSTL varraible in to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to use JSTL varraible in to jsp" Watch "How to use JSTL varraible in to jsp" New topic
Author

How to use JSTL varraible in to jsp

Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
hi friends

I have some doubts in jstl

1. how to access the jstl varraibe in to html. For example

<c:set var="css_file" value="${css_file}" scope="session">
in the css_file varriable how to use in link tag in HTML

<link rel="stylesheet" type="text/css" href="/erp/css/${css_file}.css>

if i am using this it giving error.

2. <c:set var="parmcode" value="${param.code}">
then in html
<input type = "text" name="code" value="${parmcode}">
the output showing jsut ${parmcode}.

I can give S{value} in jsp . But in the output showing "${value}"

can you sggest me. how to use it.

shall i change anything in web.xml.

In my tomcat /conf/web.xml file already having the following code

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

And mY application web.xml file located in erp/web/Web-INF/web.xml.
in that

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

Is it correct or change the web.xml file.

Please suggest me.

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

Originally posted by Vasanthan Ramakrishnan:
if i am using this it giving error.

Not showing us the error makes it hard to help you.

but in the output showing "${value}"

This means that the EL is not being evaluated in template text and is a direct result of your web.xml using the 2.3 DOCTYPE. Have you looked at the entries in the JSP FAQ to make sure that you are set up correctly?
[ December 20, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

By the way, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and most people will just go elsewhere. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
Hongli Li
Ranch Hand

Joined: Oct 29, 2006
Posts: 124
in jsp 1.2 specification, the EL ${variable} won't render, you need to use <cut > to output variable, It works in jsp 2.0 specification, if I'm right.


Do you know why this cup is useful? Because it is empty.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

Originally posted by Hongli Li:
in jsp 1.2 specification, the EL ${variable} won't render, you need to use <cut > to output variable, It works in jsp 2.0 specification, if I'm right.

That is correct. However based upon the original post, Tomcat 5 (or 6) is being used; which is JSP 2.0 capable.

The problem is that the 2.3 DTD in the web.xml is forcing the web app to run in a JSP 1.2 compatibility mode needlessly.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

The web.xml must be set up exactly as shown in this JSP FAQ entry. You cannot use a DOCTYPE and expect the correct behavior.
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
still I am not clear.

I am using Apache Tomcat Version 6.0.10

In my tomcat/conf/web.xml file having

[<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

</web-app>]

But I am developing an apllication. In my appication I will setting the web.xml file in erp/web/WEB-INF/web.xml.

In that I am set it like this

[<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">]

If I changed [http://java.sun.com/dtd/web-app_2_3.dtd] to [http://java.sun.com/dtd/web-app_2_4.dtd] is it also not working.

Is it correct I am setting in my web.xml file.

Please suggest me.

Thanks in advance.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

tomcat/conf/web.xml

You don't have to touch that file. The default for Tomcat 6 should be Servlets 2.5, so you should leave it like it is. You have to change your own web.xml, copy/pasting the definition Bear told you to. Which means settins this into erp/web/WEB-INF/web.xml.


[My Blog]
All roads lead to JavaRanch
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
Ok I am not touch.

I copied the file(tomcat/conf/web.xml) and paste into my web.xml file.
like this

[<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">]

then
In my java code I am set it

request.setAttribute("attr1","hi");

Then My html code I get ${attr1}. But the value is showing "${attr1}"

The value of attr1 is "hi". But it not showing. It showing "${attr1}"

Please suggest me. Other than web.xml any changes is there to use JSTL.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

request.setAttribute("attr1","hi");

Where is this ? in a servlet ?

My html code

Do you mean your JSP ? If it's not a JSP file, it won't get translated.

Please follow these instructions, and try again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

Originally posted by Vasanthan Ramakrishnan:
like this

[<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">]

What's with the extra [ and ]? That is not valid syntax.
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
Sorry its working.

thank you very much Bear and Christophe Verre
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
hi

1. how to use jstl varriable into Javascript.

for example :
<script type="text/javascript">
var a = ${value};
document.write("<TD>${value</TD>");
</script>

Is it correct syntax to use in Javascript. how to use this.


2. how to use JStl varriable into Xml Tag.

for example :

This is scriplet code java value I am passing to XML.

<eztag:companytag pgm_sname="<%= strpgm_name%>" dbase="<%= strd%>"
dbpass="<%= strp%>" dburl="<%= stru%>" session="<%= session%>" />

After modified in JSTL

<eztag:companytag pgm_sname="${pgm_name}" dbase="${strd}"
dbpass="${strp}" dburl="${stru}" session="${session}" />

but its Not working.

3.How to use ArrayLIst in JSTL

For example

IN Java scriplet code in JSP

<%for(int i=0;i<alist.size();i++) {
String str = String.valueOf(alist.get(i));
String str1 = String.valueOf(alist.get(i+1));
%>

<TD>STR - <%=str%> </TD>
<TD>STR1 - <%=str1%> </TD>

<% } %>

This code How to Use in JSTL.

Please refer good site to refer JSTL Tags

thanks in advance
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
Sorry
1.how to use JSTL Varriable in Javascript
<script type="text/javascript">
var a = ${value};
document.write("<TD>${value}</TD>");
</script>
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
hi

Doubts in JSTL

1. how to use JSTL varriable into Xml Tag.

for example :

java value I am passing to XML.

<eztag:companytag pgm_sname="<%= strpgm_name%>" dbase="<%= strd%>"
dbpass="<%= strp%>" dburl="<%= stru%>" session="<%= session%>" />

After modified in JSTL

<eztag:companytag pgm_sname="${pgm_name}" dbase="${strd}"
dbpass="${strp}" dburl="${stru}" session="${session}" />

but its Not working. How to use this

the "eztag" and "companytag" are the customtag. these tages available in eztaglib.tld file. I am passing the value through XML Tag.

Please suggest me . how to use.



2.How to use ArrayLIst in JSTL

For example

IN Java scriplet code in JSP

<%for(int i=0;i<alist.size();i++) {
String str = String.valueOf(alist.get(i));
String str1 = String.valueOf(alist.get(i+1));
%>

<TD>STR - <%=str%> </TD>
<TD>STR1 - <%=str1%> </TD>

<% } %>

This code How to Use in JSTL.

thanks in advance
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
Sorry for pain to ask repeatedly the same question.

Please help to solve my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use JSTL varraible in to jsp