Liferay 6.2 Media Gallery - java
<%--
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%# include file="/html/portlet/image_gallery_display/init.jsp" %>
<%
Folder folder = (Folder)request.getAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER);
long defaultFolderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", StringPool.BLANK), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
long folderId = BeanParamUtil.getLong(folder, request, "folderId", defaultFolderId);
boolean defaultFolderView = false;
if ((folder == null) && (defaultFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
defaultFolderView = true;
}
if (defaultFolderView) {
try {
folder = DLAppLocalServiceUtil.getFolder(folderId);
}
catch (NoSuchFolderException nsfe) {
folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
}
}
long repositoryId = scopeGroupId;
if (folder != null) {
repositoryId = folder.getRepositoryId();
}
int status = WorkflowConstants.STATUS_APPROVED;
if (permissionChecker.isContentReviewer(user.getCompanyId(), scopeGroupId)) {
status = WorkflowConstants.STATUS_ANY;
}
long portletDisplayDDMTemplateId = PortletDisplayTemplateUtil.getPortletDisplayTemplateDDMTemplateId(displayStyleGroupId, displayStyle);
%>
<c:choose>
<c:when test="<%= portletDisplayDDMTemplateId > 0 %>">
<%
String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
List fileEntries = DLAppServiceUtil.getGroupFileEntries(scopeGroupId, 0, folderId, mediaGalleryMimeTypes, status, 0, SearchContainer.MAX_DELTA, null);
%>
<%= PortletDisplayTemplateUtil.renderDDMTemplate(pageContext, portletDisplayDDMTemplateId, fileEntries) %>
</c:when>
<c:otherwise>
<%
String topLink = ParamUtil.getString(request, "topLink", "home");
long assetCategoryId = ParamUtil.getLong(request, "categoryId");
String assetTagName = ParamUtil.getString(request, "tag");
boolean useAssetEntryQuery = (assetCategoryId > 0) || Validator.isNotNull(assetTagName);
PortletURL portletURL = renderResponse.createRenderURL();
portletURL.setParameter("struts_action", "/image_gallery_display/view");
portletURL.setParameter("topLink", topLink);
portletURL.setParameter("folderId", String.valueOf(folderId));
request.setAttribute("view.jsp-folder", folder);
request.setAttribute("view.jsp-defaultFolderId", String.valueOf(defaultFolderId));
request.setAttribute("view.jsp-folderId", String.valueOf(folderId));
request.setAttribute("view.jsp-repositoryId", String.valueOf(repositoryId));
request.setAttribute("view.jsp-viewFolder", Boolean.TRUE.toString());
request.setAttribute("view.jsp-useAssetEntryQuery", String.valueOf(useAssetEntryQuery));
request.setAttribute("view.jsp-portletURL", portletURL);
%>
<portlet:actionURL var="undoTrashURL">
<portlet:param name="struts_action" value="/document_library/edit_entry" />
<portlet:param name="<%= Constants.CMD %>" value="<%= Constants.RESTORE %>" />
</portlet:actionURL>
<liferay-ui:trash-undo portletURL="<%= undoTrashURL %>" />
<liferay-util:include page="/html/portlet/document_library/top_links.jsp" />
<c:choose>
<c:when test="<%= useAssetEntryQuery %>">
<liferay-ui:categorization-filter
assetType="images"
portletURL="<%= portletURL %>"
/>
<%
SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, null, null);
OrderByComparator orderByComparator = DLUtil.getRepositoryModelOrderByComparator("modifiedDate", "desc");
searchContainer.setOrderByComparator(orderByComparator);
long[] classNameIds = {PortalUtil.getClassNameId(DLFileEntryConstants.getClassName()), PortalUtil.getClassNameId(DLFileShortcut.class.getName())};
AssetEntryQuery assetEntryQuery = new AssetEntryQuery(classNameIds, searchContainer);
assetEntryQuery.setEnablePermissions(true);
assetEntryQuery.setExcludeZeroViewCount(false);
int total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);
searchContainer.setTotal(total);
List results = AssetEntryServiceUtil.getEntries(assetEntryQuery);
searchContainer.setResults(results);
String[] mediaGalleryMimeTypes = null;
request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
request.setAttribute("view.jsp-searchContainer", searchContainer);
%>
<liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" />
</c:when>
<c:when test='<%= topLink.equals("home") %>'>
<aui:row>
<c:if test="<%= folder != null %>">
<liferay-ui:header
localizeTitle="<%= false %>"
title="<%= folder.getName() %>"
/>
</c:if>
<%
SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, null, null);
String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
int foldersCount = DLAppServiceUtil.getFoldersCount(repositoryId, folderId, true);
int total = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcutsCount(repositoryId, folderId, status, mediaGalleryMimeTypes, true);
int imagesCount = total - foldersCount;
searchContainer.setTotal(total);
List results = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts(repositoryId, folderId, status, mediaGalleryMimeTypes, true, searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
searchContainer.setResults(results);
request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
request.setAttribute("view.jsp-searchContainer", searchContainer);
%>
<aui:col cssClass="lfr-asset-column lfr-asset-column-details" width="<%= showFolderMenu ? 75 : 100 %>">
<div id="<portlet:namespace />imageGalleryAssetInfo">
<c:if test="<%= folder != null %>">
<div class="lfr-asset-description">
<%= HtmlUtil.escape(folder.getDescription()) %>
</div>
<div class="lfr-asset-metadata">
<div class="lfr-asset-icon lfr-asset-date">
<%= LanguageUtil.format(pageContext, "last-updated-x", dateFormatDate.format(folder.getModifiedDate())) %>
</div>
<div class="lfr-asset-icon lfr-asset-subfolders">
<%= foldersCount %> <liferay-ui:message key='<%= (foldersCount == 1) ? "subfolder" : "subfolders" %>' />
</div>
<div class="lfr-asset-icon lfr-asset-items last">
<%= imagesCount %> <liferay-ui:message key='<%= (imagesCount == 1) ? "image" : "images" %>' />
</div>
</div>
<liferay-ui:custom-attributes-available className="<%= DLFolderConstants.getClassName() %>">
<liferay-ui:custom-attribute-list
className="<%= DLFolderConstants.getClassName() %>"
classPK="<%= (folder != null) ? folder.getFolderId() : 0 %>"
editable="<%= false %>"
label="<%= true %>"
/>
</liferay-ui:custom-attributes-available>
</c:if>
<liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" />
</div>
</aui:col>
<c:if test="<%= showFolderMenu %>">
<aui:col cssClass="lfr-asset-column lfr-asset-column-actions" last="<%= true %>" width="<%= 25 %>">
<div class="lfr-asset-summary">
<liferay-ui:icon
cssClass="lfr-asset-avatar"
image='<%= "../file_system/large/" + ((total > 0) ? "folder_full_image" : "folder_empty") %>'
message='<%= (folder != null) ? HtmlUtil.escape(folder.getName()) : LanguageUtil.get(pageContext, "home") %>'
/>
<div class="lfr-asset-name">
<h4><%= (folder != null) ? HtmlUtil.escape(folder.getName()) : LanguageUtil.get(pageContext, "home") %></h4>
</div>
</div>
<%
request.removeAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
%>
<liferay-util:include page="/html/portlet/document_library/folder_action.jsp" />
</aui:col>
</c:if>
</aui:row>
<%
if (folder != null) {
IGUtil.addPortletBreadcrumbEntries(folder, request, renderResponse);
if (!defaultFolderView && portletName.equals(PortletKeys.MEDIA_GALLERY_DISPLAY)) {
PortalUtil.setPageSubtitle(folder.getName(), request);
PortalUtil.setPageDescription(folder.getDescription(), request);
}
}
%>
</c:when>
<c:when test='<%= topLink.equals("mine") || topLink.equals("recent") %>'>
<%
long groupImagesUserId = 0;
if (topLink.equals("mine") && themeDisplay.isSignedIn()) {
groupImagesUserId = user.getUserId();
}
SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, null, null);
String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
int total = DLAppServiceUtil.getGroupFileEntriesCount(repositoryId, groupImagesUserId, defaultFolderId, mediaGalleryMimeTypes, status);
searchContainer.setTotal(total);
List results = DLAppServiceUtil.getGroupFileEntries(repositoryId, groupImagesUserId, defaultFolderId, mediaGalleryMimeTypes, status, searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
searchContainer.setResults(results);
request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
request.setAttribute("view.jsp-searchContainer", searchContainer);
%>
<aui:row>
<liferay-ui:header
title="<%= topLink %>"
/>
<liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" />
</aui:row>
<%
PortalUtil.addPortletBreadcrumbEntry(request, LanguageUtil.get(pageContext, topLink), currentURL);
PortalUtil.setPageSubtitle(LanguageUtil.get(pageContext, topLink), request);
%>
</c:when>
</c:choose>
</c:otherwise>
</c:choose>
i m using Liferay 6.2 and using Media Gallery Portlet to display the images which is placed in Multiple folders. i have multiple folders which contain multiple images but the folders are arranged according to alphabetical order but my requirement is to arrange the folders which are recently updated (i,e the recently updated folder must come at the top) so can anybody please provide solution how to achieve this.
thanks in Advance.
Over-ride view.jsp of /html/portlet/image_gallery_display by either hook or ext and add following two lines below the initialization of SearchContainer object at about line# 115:
OrderByComparator orderByComparator =
DLUtil.getRepositoryModelOrderByComparator("modifiedDate", "desc");
searchContainer.setOrderByComparator(orderByComparator);
This will order your Media Gallery's folders and images descending by modified date.
Update:
If you want to control this behavior from preferences, then:
Declare and initialize these properties in init.jsp:
String sortByCol = portletPreferences.getValue("sortByCol", "title");
String sortByOrder = portletPreferences.getValue("sortByOrder", "desc");
Add following drill-downs for value selection in
configuration.jsp:
<div class="aui-column left-selector-column">
<aui:select label="Sort By" name="preferences--sortByCol--">
<aui:option label="Title" value="title"
selected="<%= sortByCol.equals("title") %>" />
<aui:option label="Create Date" value="creationDate"
selected="<%= sortByCol.equals("creationDate") %>"/>
<aui:option label="Modified Date" value="modifiedDate"
selected="<%= sortByCol.equals("modifiedDate") %>" />
</aui:select>
</div>
<div class="aui-column right-selector-column">
<aui:select label="Order" name="preferences--sortByOrder--">
<aui:option label="Ascending" value="asc"
selected="<%= sortByOrder.equals("asc") %>"/>
<aui:option label="Descending" value="desc"
selected="<%= sortByOrder.equals("desc") %>"/>
</aui:select>
</div>
Add these two lines in view.jsp below the
initialization of SearchContainer:
OrderByComparator orderByComparator =
DLUtil.getRepositoryModelOrderByComparator(sortByCol, sortByOrder);
searchContainer.setOrderByComparator(orderByComparator);
Related
Why random checkbox choosing giving error,not in serial-wise in JSP page?
I am trying to make a basic shop-billing JSP project. now when i type random product quantity with checkbox it giving error like below image. but when i checked-value with serial wise, it is not giving the error, it giving me the result what i desiring. I have also check it is empty or not. but can't able to get out of this error. how can i get rid out of it? Code: <%-- Document : order Created on : Jun 15, 2019, 3:11:06 PM Author : Riddhi --%> <%#page contentType="text/html" pageEncoding="UTF-8"%> <%#page import="java.sql.*" %> <!DOCTYPE html> <html lang="en"> <%# include file="header.jsp" %> <h2 class="text-center"> ShopBilling </h2> <p><br/></p> <% String Host = "jdbc:mysql://localhost:3306/shopbilling"; Connection connection = null; Statement statement = null; ResultSet rs = null; PreparedStatement ps=null; Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection(Host, "root", ""); StringBuilder sb = new StringBuilder(); %> <div class="row justify-content-center"> <div class="col-md-6"> <div class="row"> <div class="col-md-6"><h3>Product Details</h3></div> <div class="col-md-6 text-right"> Back to Home </div> </div> <p></p> <form action="" method="post"> <% String products[] = request.getParameterValues("products"); String items[] = request.getParameterValues("item_no"); int sum=0; if (products!= null && items!= null && products.length != 0 && items.length != 0) { for (int i = 0; i < products.length; i++) { %> <% statement = connection.createStatement(); String u=request.getParameter("u"); int num=Integer.parseInt(products[i]); String Data = "select * from products_tbl where id='"+num+"'"; rs = statement.executeQuery(Data); while (rs.next()) { %> <input type="hidden" name="id" value='<%=rs.getString("id")%>'/> <div class="form-group"> <label for="product_name">Product Name: <%=rs.getString("product_name")%></label> <input type="hidden" class="form-control" id="product_name" name="product_name" value='<%=rs.getString("product_name")%>'> </div> <div class="form-group"> <label for="product_price">Product Single Price: <%=rs.getString("product_price")%></label> <input type="hidden" class="form-control" id="product_price" name="product_price" value='<%=rs.getString("product_price")%>'> </div> <div class="form-group"> <label for="product_name">Item Quantity: <% out.println(items[i]); %></label> <input type="hidden" class="form-control" id="item_no" name="item_no" value='items[j]'> </div> <div class="form-group"> <label for="product_name">Product Total Price: <% int num1=Integer.parseInt(items[i]); int propri=Integer.parseInt(rs.getString("product_price")); out.println(num1 * propri); int gtotal= num1 * propri; %></label> <input type="hidden" class="form-control" id="item_no" name="item_no" value='items[j]'> </div> <hr> <% sum= sum + gtotal; %> <% } } } %> <div class="form-group"> <label for="product_name">Grand Total: <% out.println(sum); %></label> <input type="hidden" class="form-control" id="item_no" name="item_no" value='items[j]'> </div> <button type="print" onclick="window.print();" class="btn btn-warning">Print</button> </form> </div> </div> <%# include file="footer.jsp" %> </html>
I think the problem in your code is with <input type="text" name="item_no" /> because every row in your above code has checkbox , when you submit your form only selected checkbox is passed , but all <input type="text" name="item_no" /> is passed even the null where you didn't give any value , so when you iterate you get null value with that as well .Now ,to solve this do like below : //give value to your check-box i.e id of that row <input type="checkbox" name="products" value ='<%=rs.getString("id")%>' /> //pass that id with your input type i.e item_no_1 ..etc <input type="text" name='item_no_<%=rs.getString("id")%>' /> And then to get only particular value of Product Quantity where you have selected Checkbox do like below : String products[] = request.getParameterValues("products"); if (products!= null && items!= null && products.length != 0 && items.length != 0) { for (int i = 0; i < products.length; i++) { //your code <div class="form-group"> <label for="product_name">Product Total Price: <% //getting item value of that selected checkbox int item_no=Integer.parseInt(request.getParameter("item_no_" + products[i])); int propri=Integer.parseInt(rs.getString("product_price")); out.println(num1 * propri); int gtotal= num1 * propri; %></label> <input type="hidden" class="form-control" id="item_no" name="item_no" value='items[j]'> </div>
Number Format Exception JSP Page with cookies
I wrote this small code for handling cookies.However,when i click on the "next" button it throws a java.lang.NumberFormatException: For input string: "current" Code: <%#page import="java.util.*"%> <% int current=0; Cookie[] cookies = request.getCookies(); Cookie cookie = null; if(cookies != null){ for(int i=0;i<cookies.length;i++){ if(cookies[i].getName().equals("last")) cookie = cookies[i]; } } if(cookie != null){ String btn = request.getParameter("button"); if(btn != null){ if(btn.equals("next")) current = Integer.parseInt(cookie.getValue()) + 1; else current = Integer.parseInt(cookie.getValue()) - 1; } } response.addCookie(new Cookie("last",String.valueOf("current"))); out.println(current); %> <html> <head> </head> <body> <form method="post"> <input type="submit" name="button" value="prev" /> <input type="submit" name="button" value="next" /> </form> </body> </html>
You set the cookie to value "current" String.valueOf("current") but you want String.valueOf(current)
Accessing selected dropdown items using Java
I have a dropdown which consist the language names. I am setting the value and displaying name of the dropdown by using a hashmap. <form action="TextTranslation" method="post" class="form" role="form" > <div class="row"> <div id = "imageView" class="col-lg-8 center-block "> <div class="btn-group"> <select name="country"> <% Map<String,String> langCode = x.getCountryList(); for( Object key :langCode.keySet() ) {%> <option value="<%=(String)key%>"><%=langCode.get(key) %> </option> <% System.out.println((String)key); } String name = request.getParameter("country"); request.setAttribute("code", name); %> </select> </div> <input type="submit" class= "btn btn-image" value="Translate"> Search Text </div> </div> </form> Values are passed correctly to dropbox as it print all the values in console. the set attribute is accessed in the particular servlet. But it gives a null value. Do you have any idea?Thank you in advance UPDATED <select name="country"> <% Map<String,String> langCode = x.getCountryList(); for( Object key :langCode.keySet() ) {%> <option value="<%=(String)key%>"><%=langCode.get(key) %> /option> <% System.out.println((String)key); } String name = request.getParameter("country"); %> </select> <input type="hidden" name="code" value = <%= name%>/> . In the servlet I used, request.getParameter("code");
update your jsp likewise, <form...> ... <input type="hidden" name="code" value = <%= name%>/> .... </form> then get it from your servlet likewise, request.getParameter("code"); // will return value of code NOTE : Remove from your jsp-code if above solution you gonna implement then, request.setAttribute("code", name);
error TLD use in a jsp file
I have the following line of code in a JSP File in my web app t <% if (!maintenance) { %> <customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{"authentification.Login.action.logInApplicationLabel"},new String[]{"logInApplication()"}) %>"/> <% } else { %> <customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{},new String[]{}) %>"/> <% } %> The error message that I get is: /WEB-INF/tags/DialogEntry.tag According to the TLD , the value attribute accepts no expression How do I resolve this problem? DialogEntry.tag: <%# attribute name="entry" rtexprvalue="true" type="com.presentation.generic.session.DialogEntry" %> <%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <%# taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %> <%# taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %> <%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%# taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic" %> <script type="text/javascript"> //confirm("<c:out value="${entry.id}" /> début"); var <c:out value="${entry.id}" /> = new YAHOO.widget.Dialog("<c:out value="${entry.id}" />", { width: "<c:out value="${entry.size}" />", <c:if test="${\"\" != entry.visible}"> visible:true, </c:if> <c:if test="${\"\" == entry.visible}"> visible:false, </c:if> close:false, draggable :false <c:if test="${\"\" != entry.effect}"> ,effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5} } ); </c:if> <c:if test="${\"\" == entry.effect}"> } ); </c:if> <c:if test="${\"false\" != entry.hasButtons}"> var myButtons = [ <c:forEach var="button" items="${entry.buttons}" varStatus="ind"> { text:"<bean:message key="${button}"/>", handler:function() {<c:out value="${entry.functions[ind.index]}" />;}, isDefault:true } <c:if test="${!empty entry.buttons[ind.index+1]}"> , </c:if> </c:forEach> ]; <c:out value="${entry.id}" />.cfg.queueProperty("buttons", myButtons); </c:if> // confirm("<c:out value="${entry.id}" /> fin - debut script"); if($.browser.msie && $('#header').size() > 0 ){ // confirm("<c:out value="${entry.id}" /> fin - debut script IE"); var menuWidth = $("div#menu").get(0).clientWidth; var headerHeight = $("div#header").get(0).clientHeight; var width = document.body.clientWidth; var contentWidthConnected = width - menuWidth; if( $('div#content_onglets').size() > 0){ // confirm("<c:out value="${entry.id}" /> fin - debut script IE Onglet"); <c:out value="${entry.id}" />.cfg.queueProperty("x", 50); <c:out value="${entry.id}" />.cfg.queueProperty("y", 0); } else{ // confirm("<c:out value="${entry.id}" /> fin - debut script IE Pas Onglet"); <c:out value="${entry.id}" />.cfg.queueProperty("x", menuWidth + 50); <c:out value="${entry.id}" />.cfg.queueProperty("y", headerHeight ); } // confirm("<c:out value="${entry.id}" /> fin - FIN script IE"); } else{ <c:out value="${entry.id}" />.cfg.queueProperty("fixedcenter", true); } // confirm("<c:out value="${entry.id}" /> fin script"); <c:out value="${entry.id}" />.render(); // confirm("<c:out value="${entry.id}" /> fin script 2"); </script>
Either escape your inner quotes: <% if (!maintenance) { %> <customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry(\"dialog1\",\"225px\",\"true\",\"true\",new String[]{\"authentification.Login.action.logInApplicationLabel\"},new String[]{\"logInApplication()\"}) %>"/> <% } else { %> <customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry(\"dialog1\",\"225px\",\"true\",\"true\",new String[]{},new String[]{}) %>"/> <% } %> Or use single quotes: <% if (!maintenance) { %> <customTag:DialogEntry entry='<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{"authentification.Login.action.logInApplicationLabel"},new String[]{"logInApplication()"}) %>'/> <% } else { %> <customTag:DialogEntry entry='<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{},new String[]{}) %>'/> <% } %> Reading the error message is quoted with " which must be escaped when used within the value you see that having " inside your text is the cause. Hence, either your text is not defined with " (the second solution, where you use ') or the " inside the text have a \ to escape them and make them actual characters in the text.
Escape all " with \" inside your block: entry=""
How to send variable in action java class to jquery?
When I click on the button will be equal to the amount of undefind while the amount is equal to 1 in jsp page : <% String err1 = (String) request.getAttribute("err2"); int code = 0; if (err1 != null){ code = Integer.parseInt(err1); System.out.println(" code " + code); } %> <button type="button" id="btnok">ok</button> <br /> <%if(code == 3){ %> <input id="txtcode" type="hidden" value="1" /> <%}%> <br /> in jquery code: $(document).ready(function() { $("#btnok").click(function(event) { var xxx = $("#txtcode").val(); alert("xxx 1 test + " + xxx); }); });
The most likely reason is that the condition: <%if(code == 3){ %> <input id="txtcode" type="hidden" value="1" /> <%}%> is not being met and the input is not being inserted to the DOM. Reload the page and view the page source to see if the input is inserted.