struts resource bundle properties file not mapping some keys - java

I'm starting to study struts and I have a problem using resource properties file
some text on page is displayed as this:
???login.message???
???login.username???
???login.password???
but some other messages are correctly taken from properties file. I think that the propertis file is correctly configured but I'm missing something to display anything correctly.
the file ApplicationResources.properties
# Resources for Login Project
# Struts Validator Error Messages
# These two resources are used by Struts HTML tag library
# to format messages. In this case we make sure that errors
# are red so that they can be noticed.
errors.header=<font color="red">*
errors.footer=</font>
#errors associated with the Login page
error.username.required=username required.
error.password.required=password required
error.login.invalid=The system could not verify your username or password. Is your CAPS LOCK on? Please try again.
#login page text
login.title=this is a title
login.message=please log in
login.username=username:
login.password=password:
login.button.signon=Log In
#loggedin page text
loggedin.title=Login Project
loggedin.msg=Benvenuto, {0}. You are now logged in.
"error.login.invalid" is correctly displayed and "error.username.required" too
the login label not
this is my jsp page
<%# 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">
<%# taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html:html locale="true"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<fmt:bundle basename="ApplicationResources"/>
<title><fmt:message key="login.title"/></title>
</head>
<body>
<html:errors property="login"/>
<html:form action="login.do" focus="userName" >
<table align="center">
<tr align="center">
<td><H1><fmt:message key="login.message"/></H1></td>
</tr>
<tr align="center">
<td>
<table align="center">
<tr>
<td align="right">
<fmt:message key="login.username"/>
</td>
<td align="left">
<html:text property="userName"
size="15"
maxlength="15" />
<html:errors property="userName" />
</td>
</tr>
<tr>
<td align="right">
<fmt:message key="login.password"/>
</td>
<td align="left">
<html:password property="password"
size="15"
maxlength="15"
redisplay="false"/>
<html:errors property="password" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<html:submit>
<fmt:message key="login.button.signon"/>
</html:submit>
</td>
</tr>
</table>
</td>
</tr>
</table>
</html:form>
</body>
</html>
Can you help me ?
tkz

Your
<fmt:message ... />
tags need to be inside an
<fmt:bundle ... >
tag. Currently you are closing your bundle tag right away
<fmt:bundle basename="ApplicationResources"/>
Instead, open it
<fmt:bundle basename="ApplicationResources">
and close it
</fmt:bundle>
when you no longer need it, possibly at the end of your JSP. Nest your
<fmt:message key="login.title"/>
tags inside it.

Related

Looping over object array and using c:if jstl in a JSP

I am currently working on a small web app project. The homepage has a link that, once clicked, calls a servlet that retrieves data from a database (in the form of an arraylist of objects), adds arraylist to session(as customers), and redirects to a jsp where the objects (customers) are displayed in a table. There is a "more details" column where each row has a button which submits a form, to another jsp, with a hidden input value with customerNumber as its value and num as its name.
I want, in the second jsp, to loop over all customers and only display the one whose customerNumber matches the one sent from the first jsp.
Current code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<% String hidden = request.getParameter("num"); %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Customer Details Page</title>
</head>
<body>
<div>
<c:forEach var="c" items="${customers}">
<c:if test = "${hidden == c.customerNumber}">
<table>
<thead>
<tr>
<th>Customer Phone</th><th>Customer Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>${c.phone}</td><td>${c.country}</td>
</tr>
</tbody>
</table>
</c:if>
</c:forEach>
</div>
</body>
</html>
The above code only prints the table heading. Any help appreciated.
Found the issue, was trying to access variable from scriplet directly from jstl tags. The following code works fine:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String hidden = request.getParameter("num");
pageContext.setAttribute("reqNum",hidden);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Customer Details Page</title>
</head>
<body>
<div>
<c:forEach var="c" items="${customers}">
<c:if test = "${reqNum == c.customerNumber}">
<table border="1">
<thead>
<tr>
<th>Customer Phone</th><th>Customer Country</th>
</tr>
</thead>
<tbody>
<tr>
<td><c:out value="${c.phone}" /></td><td><c:out value="${c.country}" /></td>
</tr>
</tbody>
</table>
</c:if>
</c:forEach>
</div>
</body>
</html>
Instead of using
<td>${c.phone}</td><td>${c.country}</td>
You can try:
<td><c:out value="${c.phone}" /></td><td><c:out value="${c.country}" /></td>

<c:url> tag and contextPath doesn't display properly path

I want to redirect a client to following paths when a particural text is clicked, but only Query and Remove works properly. My contextPath is "basics" and the jsp is displayed with path "http://localhost:8080/basics/". When i click on Update or Add user, then it redirects me to "http://localhost:8080/basics/basics/users" (the jsp file is users.jsp) but it should redirects respectively to "http://localhost:8080/basics/user/update/${customer.id}" and "http://localhost:8080/basics/user/add" What's wrong with that code?
users.jsp:
<%# 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>
<title>Users</title>
//...style
</head>
<body>
<c:set value="${pageContext.request.contextPath}"
var="contextUrl" />
<c:set value="${contextUrl}/user/add" var="addUserUrl" />
<table style="width: 100%">
<tr>
<th>#ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
<td colspan="3"
style="background-color: #0CF323; text-align: center; border-top-color: #0CF323; border-right-color: #0CF323">
Add user
</td>
</tr>
<c:forEach var="customer" items="${customers}">
<c:set value="${contextUrl}/user/update/${customer.id}"
var="updateUserUrl" />
<c:set value="${contextUrl}/user/remove/${customer.id}"
var="removeUserUrl" />
<c:set value="${contextUrl}/user/${customer.id}" var="userUrl" />
<tr>
<td><c:out value="${customer.id }" /></td>
<td><c:out value="${customer.name }" /></td>
<td><c:out value="${customer.age }" /></td>
<td><c:out value="${customer.country.country }" /></td>
<td style="background-color: #17D0F5"> Query </td>
<td style="background-color: #FF8000"> Update </td>
<td style="background-color: #EC2727"> Remove </td>
</tr>
</c:forEach>
</table>
</body>
</html>
Try to replace this:
Add user
With using double quote "" and adding var="userVar":
Add user
And use the ${userVar} where you want.

org.apache.jasper.JasperException: File "/WEB-INF/spring-form.tld" not found

hi I am using Spring mvc, servlet, jsp, oracle i am getting this error:'org.apache.jasper.JasperException: File "/WEB-INF/spring-form.tld" not found' can anybody tell me how to fix this
my jsp page looks like
ContactForm.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> --%>
<!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>
<div align="center">
<h1>New/Edit Contact</h1>
<form:form action="saveContact" method="post" modelAttribute="contact">
<table>
<form:hidden path="id"/>
<tr>
<td>Name:</td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td>Email:</td>
<td><form:input path="email" /></td>
</tr>
<tr>
<td>Address:</td>
<td><form:input path="address" /></td>
</tr>
<tr>
<td>Telephone:</td>
<td><form:input path="telephone" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Save"></td>
</tr>
</table>
</form:form>
</div>
</body>
</html>
tld file and place in WEB-INF folder.
Download Jar : spring-webmvc-3.0.x.RELEASE.jar and put it in your build path or if you are working with maven project, add below entry in your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.13.RELEASE</version>
</dependency>
This jar contains Spring form tag libs.

Creating web dynamic project with Eclipse EE IDE

I am a newbie trying to create a simple web application using JSP and Mysql.
I am using following thing:
Eclipse EE IDE
Tomcat 7.0
Dtabase: MySQL
MySQL Connector
In my page I have row user add row dynamically that s work fine. I want my values should get stored in database after submit.I have searched lot on net but not find anything which can solve problem.I am giving code of current page.I know have to do connection also however I tried but not succeeded.
Thanks in advance.
JSP & Javascript:
<%# 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>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function() {
$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
$('#mytable tbody>tr:last #name').val('');
$("#mytable tbody>tr:last").each(function() {this.reset();});
return false;
});
});
</script>
</head>
<body>
<form>
<a id="add" href="javascript:void(0)">Add another Credit card</a>
<table id="mytable" width="300" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr class="person">
<td><input type="text" name="name" id="name" /></td>
<td><input type="button" value="name" /></td>
<td><select>
<option>value1</option>
<option>value2</option></select>
<td><input type="text" name="name" id="name" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="submit">
</form>
Logout
</body>
</html>

How can I filter a table displayed using Expression Language in JSP?

Here's my code that I am using to display data from the database.
<%# 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://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<!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>Book List</title>
</head>
<body>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/BookTracker" user="root" password="school" />
<sql:query dataSource="${snapshot}" var="result">
SELECT * from BookTrackerSystem;
</sql:query>
<table border="1" width="100%">
<tr>
<th>Book ID</th>
<th>Book Name</th>
<th>Book Author</th>
<th>Book Genre</th>
<th>Book Description</th>
<th>Book Due Date</th>
<th>Book Status</th>
<th>Full Name</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}" /></td>
<td><c:out value="${row.bookName}" /></td>
<td><c:out value="${row.bookAuthor}" /></td>
<td><c:out value="${row.bookGenres}" /></td>
<td><c:out value="${row.bookDesc}" /></td>
<td><c:out value="${row.bookDueDate}" /></td>
<td><c:out value="${row.bookStatus}" /></td>
<td><c:out value="${row.fullname}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>
What I want to do, using a simple textbox I want to be able to filter the table displayed using the code above, I believe I can do it using jQuery but is jQuery compatible with Expression language or is there any other method I can make use of?
Despite the fact almost nobody will support you in what you are doing :) .. I mean all is in JSP..
The exact answer is the following:
Add an html form with a textbox.
Add code that reads the textbox value as request.getParameter().
http://www.tutorialspoint.com/jsp/jsp_form_processing.htm
Add the value from (2) into your query <sql:param value="..." /> and add where clause. Perhaps, you will need IF for two cases: a) filtering off - no text value and no where b) filtering on - text value exists and where used.
This will be a server-side processing (filtering) though.
If you want client-side filtering consider using DataTables http://www.datatables.net/

Categories