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"%>
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.
I'm unable to pass variables from a.jsp to b.jsp, following is what I tried and the output. Can someone please help? Thanks.
a.jsp
start including
<jsp:include page="b.jsp">
<jsp:param name="somevar" value="zzzz" />
</jsp:include>
stop including
b.jsp
${somevar}
${param.somevar}
<%=request.getParameter("somevar")%>
output
start including
null
stop including
You have to set your param before include.
start including
<jsp:params>
<jsp:param name="somevar" value="zzzz" />
</jsp:params>
<jsp:include page="b.jsp">
</jsp:include>
stop including
And can u try this in b.jsp:
<%=request.getParameter("somevar");%>
What is output?
Try the following code:
home.jsp
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page session="false"%>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Hello world!</h1>
<jsp:include page="b.jsp">
<jsp:param name="something" value="something" />
</jsp:include>
<h1>Bye World</h1>
</body>
</html>
In the b.jsp page use the following code.
<%# 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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Param example</title>
</head>
<body>
<h1>
<c:out value="${param.something}" />
</h1>
</body>
</html>
The output must be
Hello world!
something
Bye World
Try to avoid java code in JSP pages as it is not advisable. For more details, have a look at this answer How to avoid Java Code in JSP-Files?
I am only entering the code which is giving me error
My controller class has the following method
#RequestMapping(method=RequestMethod.GET, value="/displayUser")
public String displayUsers(Model model)
{
model.addAttribute("Users", userDetailsService.listUsers());
return "displayUser";
}
My Service class has the following method
public List<UserDetails> listUsers()
{
Query que=hibernateSessionFactory.openSession().createQuery("select userName from UserDetails");
List<UserDetails> listOfUsers=null;
try {
listOfUsers= que.list();
} catch (Exception e) {
System.err.println("Error");
}
return listOfUsers;
}
I want to list all the usernames on my JSP, so I used JSTL
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%# page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Display User</title>
</head>
<body>
<c:forEach var="Users" items="${Users}">
${Users.userName}
</c:forEach>
</body>
</html>
I am getting the following error for the above code.
javax.el.PropertyNotFoundException: Property 'userName' not found on type java.lang.String
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
javax.el.BeanELResolver.property(BeanELResolver.java:325)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
org.apache.el.parser.AstValue.getValue(AstValue.java:183)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
org.apache.jsp.WEB_002dINF.views.displayUser_jsp._jspx_meth_c_005fforEach_005f0(displayUser_jsp.java:119)
org.apache.jsp.WEB_002dINF.views.displayUser_jsp._jspService(displayUser_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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).
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