calendar with struts 2 - java

I currently work with struts2 and I need to display a calendar
in my jsp page and retrieve the date in yyyy-MM-dd
I try with this code
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<!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>Insert title here</title>
<sx:head cache="false" compressed="false" />
</head>
<body>
<sx:datetimepicker name="date achat" label="Format (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
</body>
</HTML>
but while running the schedule does not appear
and just this label is displayed
Format (yyyy-MM-dd):
best regards
franco

Try the following example
Struts2 DateTimePicker

Related

How to fix the problem that prevents a textbox from caching in jsp?I need to stop a particular text box from displaying the previously entered data

I am trying to create a login page using J2EE. But, whenever I place the cursor on employee id, it displays the previous entries. This might be due to browser caching or caching from the database. How to fix this issue?
I have already tried using the following header code:-
<%# page language="java" import="java.util.*" contentType="text/html;
charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", -1);
%>
<!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">
< meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<title>
Photo of form
You could try the very old method of setting autocopmlete to off inside your input tag.
autocomplete="off"

JSTL not recognized in JSP after adding jar

I added jstl-1.2.jar to my lib folder, then I included:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
on top of my JSP file and still It says `Unknown tag (c:forEach).
welcome.jsp
<%# 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" %>
<!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>Insert title here</title>
</head>
<body>
<c:forEach>
</c:forEach>
</body>
</html>
Project construction HERE
1.Use only jstl-1.2.jar
2.Try to get some items to iterate, for example:
<c:forEach items="${requestScope.list}" var="item">
</c:forEach>

<sec:authorize does not work in some jsp pages

I want to show the Authenticated user's firstname and lastname. I put related code segment in Header.jsp and include it in two other jsp pages, Index.jsp and News.jsp.
When Header.jsp included in News.jsp, it works correctly and displays Authenticated user's firstname and lastname, but when it's include in Index.jspm it doesn’t show anything.
My pages structure looks like blow:
Header.jsp
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="usertext">
<span id="loginedUserFullname">
<sec:authorize access="isAuthenticated()">
<sec:authentication property="principal.firstname" />
<sec:authentication property="principal.lastname" />
<span class="welcome">welcome</span>
<a class="logout" href='/view/cpanel/Logout.jsp'>(loge out)</a>
</sec:authorize>
</span>
</div>
</nav>
Index.jsp
<%# page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<jsp:include page="/includes/front/Head.jsp"></jsp:include>
<title></title>
</head>
<body>
<jsp:include page="/includes/front/Header.jsp"></jsp:include>
<jsp:include page="/includes/front/Scripts.jsp"></jsp:include>
</body>
News.jsp
<%# page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<jsp:include page="/includes/front/Head.jsp"></jsp:include>
<title></title>
</head>
<body>
<jsp:include page="/includes/front/Header.jsp"></jsp:include>
<jsp:include page="/includes/front/Scripts.jsp"></jsp:include>
</body>
whats wrong with <sec> that doesn't work in the Index.jsp?
Is it possible that Index.jsp does not require the user the be authenticated but News.jsp does?

Good JSP code structure for header and footer

I currently have following code structure of my JSP pages:
MyPage.jsp
<jsp:include page="header.jsp"/>
Specific page content
<jsp:include page="footer.jsp"/>
However, this means that the header and footer code do not have a correct HTML structure. For example, this is simplified header and footer code:
header.jsp
<!DOCTYPE html>
<html lang="en">
<head>
<title>${param.pageTitle}</title>
</head>
<body>
<div class="container" style="margin-top: 80px;">
footer.jsp
</div>
</body>
</html>
As a result, IDE gives a warning about "missing start tag" / "missing end tag". I don't feel good about disabling the warning entirely since it may find legitimate issues with HTML structure.
Is there a cleaner way to structure the JSP code so that I can still reuse header and footer code in some good way?
Might be this is helpful. Please have a look.
\home.jsp // Base Page
\parts\meta.jsp // To hold page meta information. Useful when working with SEO
\parts\header.jsp // Resources CSS, images,
\parts\footer.jsp // Resources JS
Remember
Use <%#include> because it is static include and <jsp:include> is dynamic include.
When you use <jsp:include> the file will be included at runtime.
When you use <%#include> file will be included at compile time.
So here is code snippet.
1) home.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>
<%# include file="parts/meta.jsp" %>
<title>Home Page</title>
<%# include file="parts/header.jsp" %>
</head>
<body>
<div class="view">
<div class="pages">
<jsp:include page="parts/page-body.jsp"></jsp:include>
</div>
</div>
<%# include file="parts/footer.jsp" %>
</body>
</html>
2) meta.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">
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
3) header.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">
<link href="http://fonts.googleapis.com/css?family=Roboto:400,300,500,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/my-page.css">
<link rel="stylesheet" href="css/my-icon.css">
<link rel="icon" href="img/icon.png">
4) footer.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">
<script type="text/javascript" src="js/my-app.js"></script>
<script type="text/javascript" src="js/my-app-service.js"></script>
Thanks :)
What you are doing is complete wrong way of doing programming. We use include tag to insert a complete page in another page. We do not divide a page in parts. So the correct approach should be to include two separate jsp pages as header and footer in your main jsp page without distorting it. That is your MyPage.jsp should be :-
<!DOCTYPE html>
<html lang="en">
<head>
<title>${param.pageTitle}</title>
</head>
<body>
<jsp:include page="header.jsp"/>
Specific page content
<jsp:include page="footer.jsp"/>
</body>
</html>
and header.jsp and footer.jsp should be :-
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
Specific page content
</body>
</html>
This is the proper structure of a page.

Warning in an Anchor Tag in a JSP File

I am able see the warning in a jsp file for the anchor tag.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page import="java.util.Date" %>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Bills Added</title>
</head>
<body>
<h1>Bills Added</h1>
<p>You have added a new bill at</p>
<c:url var="mainUrl" value="/bills/add" />
<p>Return to Main List</p>
</body>
</html>
In the line <p>Return to Main List</p> its showing a warning:
WebContent/WEB-INF/jsp/${mainUrl} not found.
I can understand about the c:url tag but in the href with the place holder ${mainUrl}, then its showing warning in all the files which I have placed like this format. Please neeed suggestion to fix this or why am getting this?

Categories