Requests: Please only answer if you know implications in depth.
Related Question that I found help from: Nested expression in JSP/JSTL
I want to make my links, paths, and variables (for images, scripts, and other pages and includes) generic so that refactoring or changes file locations in future would make no big problems.
What I thought was to make:
variables.jsp:
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%#taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<c:set var="mainDir" value="${pageContext.request.contextPath}/view/jsp" />
<c:set var="resourcesDir" value="${mainDir}/resources" />
header.jsp
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%#include file="variables.jsp" %>
<html>
<head><title>${pageTitle}</title></head>
login.jsp
<c:set var="pageTitle" >
<spring:message code="pageTitle.login" />
</c:set>
<%#include file="${mainDir}/common/header.jsp" %>
<body>...
...
...
<%#include file="${mainDir}/common/footer.jsp" %>
Please observe the includes and c:sets / c:outs with spring:messages.
What is the proper way to do what I want to (if my current strategy is not sane).
Related
I have a jsp file that receives data from a Spring MVC Controller
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<%# page session="false"%>
<form:form action="" commandName="someDetail">
<form:input path="name" class="form-control" />
<form:input path="address" class="form-control" />
This successfully displays the data inside a textbox. I want to display the data as an ordinary text without the textbox. I have tried printing it as
${address}
but it does not work. How do I print the values without the textbox?
As there is a commandName="someDetail", I assume there is an object called someDetail in the model.
If so, you just have to write ${someDetail.address} to print the address in the generated html.
hi i have this in a jsp page
<input type="text" id="jsonBom" value='${excNotice}'/>
value='${excNotice}' is been interpreted as text in the jsp i get this text : ${excNotice} ... not the content of this variable that is been passed by spring controller ... very strange ...
I have all the tag libs needed in the jsp ,
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
I am trying to use JSTL for my index.jsp page, but for some reason each time after packaging project to .war and running with Tomcat it gives me following errors:
HTTP Status 500 - /index.jsp (line: 12, column: 0) Unterminated <c:if tag
or
HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
From what I found on google, there are 2 ways to install JSTL into your Maven project:
1) Add this to pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
2) Add some jars to WEB-INF/lib, but here's the problem: no such folder was automaticaly created and if I do it manually it does not help. Project structure looks like this:
The code of index.jsp is the following:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
So, what should I do to make those work? I can't find any guide or piece of information that could help me solving this. Thanks for having a look at my problem!
Just what compiler tells you: Unterminated c:if tag:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
Look at line 4 of your jsp:
<title><c:if> Tag Example</title>
It must be
<title><c:if> Tag Example </c:if></title>
EDIT: As seems that I explained badly, I have tested in a running web-app, and this way (that is just what I was trying to explain) works:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
We have an running application that is developed in struts-2.0.14. In this we used Ajax theme for displaying contents.
This ajax theme is running properly in all browsers except IE9 browsers, In IE9 this ajax theme making problem . The result is showing in new tab instead of showing in target element(div) specified by targets property.
Parent Page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<s:head theme="ajax" debug="false" />
</head>
<body>
<s:url id="changePwd" action="changePassword" />
<s:div theme="ajax" id="pwdDiv" executeScripts="true" href="%{changePwd}" loadingText="Loading..."/>
</body>
</html>
Inner page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<s:form action="changePassword" id="resetPassword" name="resetPassword">
<s:textfield name="username" id="username" />
<s:password showPassword="true" name="newpassword" id="newpassword" value="%{newpassword}"/>
<s:password showPassword="true" name="confirmpassword" id="confirmpassword" value="%{confirmpassword}"/>
<s:submit value="Confirm" showLoadingText="false" onclick="clearMsg();" theme="ajax" targets="pwdDiv" executeScripts="true" cssClass="userbutton" />
</s:form>
When Submitting the form in Inner Page the resulting page is popup into new tab. actually it should replace the content of pwdDiv.
Note: the same working properly in other browsers including (IE7,8)
Update:
making showLoadingText as true making the request as Ajax but the values are passed as null (password,confirm password ect,. -all fields)
Adding type="button" in s:submit button solve the problem. Don't know what is behind this !
<s:submit **type="button"** value="Confirm" showLoadingText="false" onclick="clearMsg();" theme="ajax" targets="pwdDiv" executeScripts="true" cssClass="userbutton" />
We have the following code (listed below) in our JSP. We are seeing the action configured in the href of the div id=pwcercontainer being called twice. Can't work out exactly why. Replacing the containing sx:div label="Admin Record Deployment" with a plain non-struts div causes the action to be called only once. We can't see anything in the documentation for sx:div that explains this behavior.
Does anyone know anything about this or have similar experience?
Thanks.
NCF
<%# page language="java" %>
<%# taglib uri="/WEB-INF/tags/c.tld" prefix="c" %>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%# taglib uri="/WEB-INF/tags/arcade.tld" prefix="arcade" %>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<s:url id="pwcerAjax" action="pwcerajax" method="start" includeParams="none"/>
<s:url id="pwAjax" action="pwajax" method="start" includeParams="none"/>
<s:url id="listPendingDeploymentsLink" action="listPendingDeployments" namespace="/"/>
<s:url id="record" action="recordDeploymentFragment" method="showAdminRecord" namespace="/"/>
<sx:div label="Admin Record Deployment" >
<!-- Div where content will be displayed -->
<sx:div id="pwcercontainer" href="%{pwcerAjax}" showLoadingText="false" indicator="recordImage" preload="true">
</sx:div>
<div id="loadingContainer"><img id="recordImage" src="images/ajaxLoadingAnimation.gif" style="display:none" alt="loading animation"/></div>
</sx:div>
I have hit this issue many times now and it is always down to an error on my part. Either returning a fragment that contains the calling piece of code:
<s:url id="getDeployQueue" action="deploymentQueue" />
<sx:div href="%{#getDeployQueue}" formId="queueForm" executeScripts="true" autoStart="true" updateFreq="3000" preload="false" showLoadingText="false" listenTopics="refreshqueue" id="deploymentQueue" >
THE CODE RETURNED in HERE CONTAINS THE s:url id="getDeployQueue" duplicating it and resulting in double calls
</sx:div>
Or i have been setting the target attribute of another ajax tag to be an sx:div when I really should be updating it using a dojo topic.
Hope this helps somebody
Neil