Good day all,
I saw <html:html></html:html> from a jsp page in a java project.
Would like to ask what is the difference between these html tags.
Kindly advise.
The example code is as follow:
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<head>
</head>
<body>
<!-- some html code here -->
</body>
</html:html>
<html:html> uses the struts-html tag library, where <html></html> is just plain old html.
You can read all about the struts-html taglib here.
both are same.html:html is struts 1 tag which is equal to basic HTML's html tag.
Related
I wanted to insert html code to a jsp page so I used normal spring controller populated my model with html items, then once I start to render the data on the view ,it show the user a row html tags rather than an actual elements like:
<p> <strong> Description:</strong></p>
I wanted to show the user an actual strong text not the tag itself ,anyone knows how to achieve that?
my view is like that:
<%# page isELIgnored ="false" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<c:out value="${Description}" escapeXml="false" />
</body>
</html>
any Idea how to solve it?
Edit : part of the code where I send the html :
model.addAttribute("Description", jobpost.getDescription()
.replace("<", "<")
.replace(">", ">")
.replace("&", "&")
.replace(""", "\"")
.replace("'", "\\"));
Edit 2 : it finally worked guys It was a problem with the above code I forgot to insert ; at the end of & lt;
You can try wrapping the field with <b> or <h2>tag
<%# page isELIgnored ="false" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<b><c:out value="${Description}" escapeXml="false" /></b> // like this
</body><
/html>
I am developing a simple Struts 1.x web application and there's a file named success.jsp and this is the sample code:
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%# taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%# taglib uri="http://struts.apache.org/tags-nested" prefix="nested"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>success.jsp</title>
<html:base/>
</head>
<body>
Go to myStart
</body>
</html:html>
By default, <html>was used instead of <html:html>, may I know what is the major difference between these two elements? Is it necessary to specify the uses of them? Besides, what is the major function for <html:base/> element?
Btw I found some definitions for these elements but I need clarification:
<html:html> Renders an HTML <html> element with language attributes extracted from the user's current Locale object, if there is one.
<html:base> Renders an HTML element with an href attribute pointing to the absolute location of the enclosing JSP page. This tag is valid only when nested inside an HTML <head> element. This tag is useful because it allows you to use relative URL references in the page that are calculated based on the URL of the page itself, rather than the URL to which the most recent submit took place (which is where the browser would normally resolve relative references against).
The <html:html> tag is a Struts 1.x JSP Taglib directive, declared in this line on your JSP Page:
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
These custom tag(s) are typically of the form <prefix:tagname>. The prefix declared on taglib is what binds your taglib container to the list of markups available in the taglib.
In essence <html:html> tells the taglib, prefixed html to render a html element when JSP is rendered.
So to answer your question <html> is a HTML directive while <html:html> is a Struts JSP taglib tag to generate a HTML <html> directive.
I am trying to execute the following jsp code which contains the optiontransferselect tag. However I am getting the below exception:
org.apache.jasper.JasperException: /abc.jsp(10,0) No tag "optiontransferselect label" defined in tag library imported with prefix "s"
Please find the below code i have used.
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Optiontransferselect Tag Example!</title>
</head>
<body>
<s:form>
<s:optiontransferselect label="Employee Records" name="leftSideEmployeeRecords" leftTitle="RoseIndia" rightTitle="JavaJazzUp" list="{'Deepak Kumar', 'Sushil Kumar','Vinod Kumar','Deepak Monthy','Deepak Mihanti', 'Sushil Kumar', 'Ravi Kant Kumar'}" headerKey="headerKey" headerValue="--- Please Select ---" doubleName="rightSideEmployeeRecords" doubleList="{'Amar Deep Patel', 'Amit Kumar','Chandan Kumar', 'Noor Kumar','Tammana Kumari'}" doubleHeaderKey="doubleHeaderKey" doubleHeaderValue="--- Please Select ---" />
</s:form>
</body>
</html>
Please Guide.
You are using older version of struts-core-xxx.jar in your project. Are you using 2.3.16 or above?
To use optiontransferselect tag you need to use struts-core-2.3.16 or higher..
You need to include the <s:head> tag which drags in some javascript that is needed to get the <s:optiontransferselect> tag to work.
Below is the code I have in index.jsp using jstl 1.2.
<%# taglib prefix = "c" uri="http://java.sun.com/jstl/core"%>
<% String[] setName = {"Hello", "you", "are", "using", "jstl", "in", "jsp"};
request.setAttribute("getName", setName);
%>
<html>
<body>
<table>
<tr><td>Print</td></tr>
<c:forEach var="itemName" items="#{getName}" >
<tr>
<td>${itemName}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
The output I was expecting is as below
Print
Hello
you
are
using
jstl
in
jsp
However below is what I am getting
Print
#{name}
Please let me know where I am missing
Below is the only jar file I have in WEB-INF/lib folder
jstl-1.2.jar
Thanks in advance
Fahim
Note: Adding Java and JSP tag as person who have knowledge of Java and JSP might be knowing JSTL too...
Here,
<%# taglib prefix = "c" uri="http://java.sun.com/jstl/core"%>
You're specifying the wrong JSTL taglib URL. This one is for JSTL 1.0. After JSTL 1.1 it requires a /jsp in the path. See also the JSTL 1.1 tag library documentation.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
As to the of the code (and to reply on all those duplicate answers complaining to use ${} instead), the #{} syntax will only work inside JSP when you're targeting a Servlet 2.5 / 2.1 compatible container with a web.xml conforming Servlet 2.5 spec. Tomcat 6.0 is an example of such a container. The #{} will indeed not work in JSP tags on older containers such as Tomcat 5.5 or older.
For clarity and to avoid confusion among starters, better use ${} all the time in JSP tags. Also better use self-documenting variable names.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String[] names = {"Hello", "you", "are", "using", "jstl", "in", "jsp"};
request.setAttribute("names", names);
%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>JSTL demo</title>
</head>
<body>
<table>
<tr><td>Print</td></tr>
<c:forEach items="${names}" var="name">
<tr><td>${name}</td></tr>
</c:forEach>
</table>
</body>
</html>
See also:
Our JSTL wiki page
Difference between JSP EL, JSF EL and Unified EL
In JSTL 1.2, you don't want to use #{name} in pure JSP, that's only a JSF artifact. Instead, simply use ${name}.
You need to refer items using expression language like ${name}
U r using # instead of $ before name
Let me know if this resolves.
#{name} is not a valid Java variable reference - looks like you are confusing it with JQuery selector.
Anyways try just using items="${name}"
#{name} is should be like ${name}
oh! might be the jars related to JSTL. check thins link for those jars to include in your project
Below is the final code I am using and it is running...
Posting so that someone can use it... Might help me tomorrow ;)
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% String[] setName = {"Hello", "you", "are", "using", "jstl", "in", "jsp"};
request.setAttribute("getName", setName);
%>
<html>
<body>
<table>
<tr><td>Print</td></tr>
<c:forEach var="itemName" items="#{getName}">
<tr>
<td>${itemName}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
Learning : I was using <%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %> instead of <%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
I am using Tiles within my web-application. I have a standard-layout (standard.jsp) within the tiles are used. On top of the standard.jsp are a lot of includes, concerning tag-libraries and such.
Let's do a simplified example.
standard.jsp:
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# include file="/WEB-INF/jsp/includes/include.jsp" %>
<html>
<head>
<tiles:insertAttribute name="head" flush="false"/>
</head>
<body>
<tiles:insertAttribute name="body" flush="false"/>
</body>
</html>
body.jsp:
<div id="body-div">
<p>Hello, <c:out value="${forname}" />!</p>
</div>
This prints:
Hello, !
In the tiles I would like to use the tags, but it's not working. It only works, if I add the includes to the tile-jsp.
body.jsp with includes:
<%# include file="/WEB-INF/jsp/includes/include.jsp" %>
<div id="body-div">
<p>Hello, <c:out value="${forname}" />!</p>
</div>
This prints:
Hello, John!
Is there a better way to do this or do I have to add all includes to every jsp used?
You don't need ALL includes to be present in each of your tiles, but each used tag-library in a tile must specifically be included in the using tile.
eg :
In your example, each tile using the C JSTL library should at least have the <%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> include