I am using html5 for my JSP. I have a table cell inside which I display text. For new line I added line break tag but it does not work and it displays line break tag as it is along with my text.
I display it inside my jsp as follows.
<!DOCTYPE html>
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<table>
<tr>
<td>
<c:out value="${visitInfo.referralText}" />
</td>
</tr>
</table>
visitInfo.referralText contains the text.
Try with escapeXml attribute of c:out.
<c:out value="${visitInfo.referralText}" escapeXml="false"/>
Related
I am quite new to web programming. So, here is what my problem is
I want user to enter a number on HTML and my servlet has some logic to check if the number is correct I show ajsp with one msg if not then other msg. So, this part is quite simple and i achieved it easily. But my problem is that I want to keep on doing this. So, I want once user see result.jsp. He should be directed back to form.html but with different background color.
So I tried something like this in my jsp
<%# 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>
<head>
<title>Passing the input value to a session variable</title>
<%
String bgColor = request.getParameter("COLOR");
if (bgColor == null)
bgColor = "WHITE";
%>
</head>
<body BGCOLOR="<%=bgColor%>">
<%
String msg = (String) session.getAttribute("message");
out.print(msg);
%>
<a href="login.html"> <input type="submit" value="Try again!!"
name="TRY">
</a>
This one redirects me to login.html but the color is lost. How can i pass background color to login.html so that background color is changed.
Please some suggestions.
Thanks
You need set color as a parameter to href
<a href="login.html?color='<%=bgColor%>'">
<input type="submit" value="Try again!!" name="TRY">
</a>
I have the following code in a JSP:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<body>
<table cellpadding="10">
<tr><td>one</td><td>two</td></tr>
<tr><td>three</td><td>four</td></tr>
</table>
</body>
That's the entire file.
It is in a JSP that gets put in an IFrame. I can't figure out what is interfering with the cellpadding value -- each value should be 10 pixels from the boundary of its table cell, but it isn't. What am I missing here?
Here's the output:
Here's the relevant section from Chrome's 'inspection' window:
Good night.
I'm having trouble import static html page to a JSP page with UTF-8.
My JSP is UTF-8. I Write my HTML fragment with UTF-8, but I include with <%#include file="includes/menu.html"%>, the text is with the wrong encoding.
My JSP is complex, but my html is, an simple example:
<div>
<ul>
<li>Text with Á (acentuation)</li>
</ul>
</div>
Is very simple html, containing the application menu, but this error is occurring.
A very simple JSP is:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<head>
<meta charset="UTF-8" />
<title>Example</title>
</head>
<body>
<%#include file="includes/menu.html"%>
</body>
PS: if I put directly in JSP, it works normally.
The solution to this problem is to change the menu.html to menu.jsp and on the top of the new file add
<%#page contentType="text/html" pageEncoding="UTF-8"%>
and then include this jsp in your page
<body>
<%#include file="includes/menu.jsp"%>
</body>
What are some ways (if any) to link or import a style sheet from a JSP tag called in the <body>? It would be great if I can encapsulate all necessary imports in the JSP tag.
Current State
index.jsp:
<%# page contentType="text/html; charset=utf-8" %>
<%# taglib prefix="x" tagdir="/WEB-INF/tags" %>
<html>
<head>
<!-- we have to know what css file somecontent uses and include it here -->
<!-- the tag below prints <link rel="/somecontent.css"... /> but makes sure this url is only included once -->
<x:requireOnce loc="/somecontent.css" type="css" />
</head>
<body>
<x:somecontent />
</body>
</html>
Goal
index.jsp:
<%# page contentType="text/html; charset=utf-8" %>
<%# taglib prefix="x" tagdir="/WEB-INF/tags" %>
<html>
<head>
<%-- nothing for somecontent tag here --%>
</head>
<body>
<x:somecontent />
...
</body>
</html>
somecontent.tag:
<%# tag description="some independent content" %>
<%# taglib prefix="x" tagdir="/WEB-INF/tags" %>
<%-- the inline attribute will indicate that it is in the body and shouldn't use <link> which won't work here --%>
<x:requireOnce loc="/somecontent.css" type="css" inline="true" />
<%-- this will print <script type="text/javascript" src="/somecontent.js" ...></script> --%>
<x:requireOnce loc="/somecontent.js" type="js" />
...
Is there a way to keep a reference to the position in the head tag within the JspWriter and insert content there when necessary, i.e. new link tags?
Ideally, I don't want to inline the contents of the stylesheet or use javascript to include the style sheet. Hopefully there's some way with #import, <link> or some JSP magic... Thoughts?
You could do something along the lines of what SiteMesh does.
Each requireOnce tag would just put the file to link to in a list of files, stored in a request attribute. A servlet filter would buffer the whole response, and rewrite it when completed with the head section rewritten to include all the links.
I'm using jsp:include inside json-taglib's json:property element. The problem with this is that all HTML elements from included JSP page gets stripped at some point and only plain text remains. I have already stripped all newlines so the result shoud be valid JSON data.
How do I get full HTML returned by json-taglib?
Below is a snippet demonstrating the situation.
<%# page language="java" %>
<%# page pageEncoding="UTF-8" %>
<%# page contentType="text/html; charset=UTF-8" %>
<%# taglib uri="http://www.atg.com/taglibs/json" prefix="json" %>
<json:object>
<json:property name="id" value="${element.id}" />
<json:property name="html" escapeXml="false">
<jsp:include page="/templates/generate-component.jsp">
<jsp:param name="element_id" value="${element.id}" />
</jsp:include>
</json:property>
</json:object>
Maybe you should encode the data passed to json-taglib.
Regards.
One solution is to wrap the jsp:include in <c:out> tag and (mis)use the body-as-default-value, like so:
<c:out value="${null}">
<jsp:include ...>
<jsp:param ... />
</jsp:include>
</c:out>
However, this won't work in a situation where the included JSP itself uses jsp:include.