Why my webpage displays ???? instead of contents - java

I have used Resource Bundle editor to create _hi(Hindi language) locale properties file in eclipse.
My problem is that if I run my webpage, it displays ???? instead of Hindi content.
I have provided code below. It works fine with french language
spring-servlet.xml
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="siteLang"></property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="WEB-INF/messages"></property>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="ta"></property>
<property name="cookieName" value="BalsCookie"></property>
<property name="cookieMaxAge" value="300"></property>
</bean>
form.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="spring" uri="http://www.springframework.org/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>
<link rel="stylesheet" href="<spring:theme code='color'/>" type="text/css" />
</head>
<body>
Hindi
english
<center>
<h1>${heading}</h1>
</center>
<h1>head</h1>
<form action="/SpringMVCP4/submit" method="post">
<center>
<table>
<tr>
<td><spring:message code="label.name"></spring:message></td>
<td><input type="text" name="name"></input><span> <form:errors
path="student.name"></form:errors></span></td>
</tr>
<tr>
<td class="spring"><spring:message code="label.dob" /></td>
<td><input type="text" name="dob"></input></td>
</tr>
<tr>
<td><spring:message code="label.skillSet" /></td>
<td><select name="skillSet" multiple>
<option>java</option>
<option>php</option>
<option>.net</option>
</select></td>
</tr>
<tr>
<td><spring:message code="label.mobileNo" /></td>
<td><input type="text" name="mobileNo"></input></td>
</tr>
<tr>
<td><spring:message code="label.street" /></td>
<td><input type="text" name="address.street"></input></td>
</tr>
<tr>
<td><spring:message code="label.city" /></td>
<td><input type="text" name="address.city"></input></td>
</tr>
<tr>
<td><spring:message code="label.pincode" /></td>
<td><input type="text" name="address.pincode"></input><span
style="color: red"> <form:errors
path="student.address.pincode" /></span></td>
</tr>
<tr>
<td><spring:message code="label.submit" var="submit" /></td>
<td><input type="submit" value="${submit}"></input></td>
</tr>
</table>
</center>
</form>
</body>
</html>
Please let me know the error.

Related

Some other way to display data from sql table on jsp

I have used jstl to display particular data from table named status(all columns are string type) on found.jsp. In my table I have entered 1 and 0 under status column where 1 is for IN and 0 is for OUT.
found.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<%# page import="javax.servlet.http.*,javax.servlet.*" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Found page</title>
<style>
header {
background-color:teal;
color:white;
text-align:center;
padding:5px;
}
section {
height:270px;
width:1050px;
float:right;
padding:87px;
}
footer {
background-color:black;
float:bottom;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body style="background-color:lightsteelblue;">
<header><h3>File Status!!</h3>
<br>
</header>
<font color="black">back</font>
<form action=" LogoutServlet" method="post">
<input type="submit" value="Logout" >
</form>
<form method="POST">
File Number:<input type="text" name="status" value="" size="20" />
<input type="submit" value="submit" name="submit" />
</form>
<br>
<section>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/login"
user="root" password="root"/>
<sql:query dataSource="${snapshot}" var="result">
SELECT * from status where fname="${param.status}";
</sql:query>
<table border="1" width="100%">
<tr>
<th>File Number</th>
Below is the column where 1 and 0 are shown under
<th>File Status(IN=1 and OUT=0)</th>
<th>File Department</th>
<th>Date and Time</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.fname}"/></td>
value comes from here
<td><c:out value="${row.fstatus}"/></td>
<td><c:out value="${row.department}"/></td>
<td><c:out value="${row.datetime}"/></td>
</tr>
</c:forEach>
</table>
</section>
<footer>
Copyright 2016 NSIC. All right reserved.
</footer>
</body>
</html>
I don't want 1 and 0 to be shown instead i want IN and OUT to be shown under the column and I don't want to change the database table entery from 1 and 0 to IN and OUT Is there a way I can do this?
you can do it with <c:choose> tag
<c:choose>
<c:when test="${row.fstatus=='1'}">
IN
</c:when>
<c:otherwise>
OUT
</c:otherwise>
</c:choose>

<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.

Enabling back button with Ajax

Following is my index.jsp:
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<s:head/>
<sj:head/>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="validate.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<title>My Air - Home</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<div id="mainContent">
<jsp:include page="menubar.jsp"></jsp:include>
<div id="mainContentTop">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
Following is my search.jsp:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>\
<s:form action="searchFlight" theme="css_xhtml" cssClass="form1small" name="searchFlightForm">
<div class="searchHeadersmall">Search Flight</div>
<div id="searchForm1">
<s:actionerror/>
<s:select list="#application.cityList" headerValue="--------Select--------" headerKey="select" name="searchFlightDetails.from" label="Leaving From"></s:select>
<s:select list="#application.destlist" headerValue="---------Select-------" headerKey="select" name="searchFlightDetails.to" label="Going To"></s:select>
<sj:datepicker id="date0" label="Date" name="searchFlightDetails.dateoftravel" readonly="true" minDate="0"/>
<s:select list="#{'1':'1','2':'2','3':'3','4':'4','5':'5'}" headerValue="" headerKey="" name="searchFlightDetails.noofpassengers" label="No of tickets" style="width:50%; float:left"></s:select>
<div class="inputsmall nobottombordersmall">
<s:radio label="Type" name="searchFlightDetails.nonstop"
list="#{'Y':'NonStop','N':'Normal'}"/>
</div>
<div id="submitdivid1">
<sj:submit value="Show Flights" targets="mainContent"/>
</div>
</div>
</s:form>
When form is submitted the following searchFlightSuccess.jsp is loaded in mainContent <div>:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<s:if test="#session.username!=null">
<jsp:include page="menubaruser.jsp"></jsp:include>
</s:if>
<s:if test="#session.username==null">
<jsp:include page="menubar.jsp"></jsp:include>
</s:if>
<div id="searchHeaderHistory">Search Results</div>
<div class="CSSTableGenerator">
<table>
<colgroup>
<col span="1" style="width: 5%;">
<col span="1" style="width: 10%">
<col span="1" style="width: 15%">
<col span="1" style="width: 10%">
<col span="1" style="width: 15%">
<col span="1" style="width: 15%">
<col span="1" style="width: 15%">
<col span="1" style="width: 5%">
<col span="1" style="width: 10%">
</colgroup>
<thead>
<tr>
<td colspan="9">From:<s:property
value="searchFlightDetails.from" />
To:<s:property value="searchFlightDetails.to" /></td>
</tr>
</thead>
<tbody>
<tr>
<td>Flight ID</td>
<td>Provider</td>
<td>Departure Source</td>
<td>Via</td>
<td>Via Arrival</td>
<td>Via Departure</td>
<td>Destination Arrival</td>
<td>Fare</td>
<td></td>
</tr>
<s:iterator value="searchedFlightsList" var="flights">
<tr>
<td align="center"><s:property
value="#flights.flightDetails.fid" /></td>
<td align="center"><s:property
value="#flights.flightDetails.providerDetails.pname" /></td>
<td align="center"><s:property value="#flights.sourcedepdate" />,<s:property
value="#flights.sourcedeptime" /> hrs</td>
<td align="center"><s:property
value="#flights.flightDetails.routeDetails.via" /></td>
<td align="center"><s:property value="#flights.viaarrdate" />,<s:property
value="#flights.viaarrtime" />hrs</td>
<td align="center"><s:property value="#flights.viadepdate" />,<s:property
value="#flights.viadeptime" />hrs</td>
<td align="center"><s:property value="#flights.destarrdate" />,<s:property
value="#flights.destarrtime" />hrs</td>
<td width="5%" align="center"><s:property
value="#flights.flightDetails.fares2d" /></td>
<td width="5%" align="center">
<s:form
action="passengerDetailsLink" method="get" theme="simple"
id="passengerDetailsLink_%{#flights.sid}">
<s:hidden value="%{#flights.sid}" name="sid" />
<s:hidden value="%{#flights.flightDetails.fares2d}" name="fare" />
<s:hidden value="%{searchFlightDetails.from}" name="from" />
<s:hidden value="%{searchFlightDetails.to}" name="to" />
<s:hidden value="%{searchFlightDetails.noofpassengers}"
name="passengers" />
<s:hidden value="1" name="flag" />
<sj:submit value="Book" targets="mainContent"
cssClass="orangebuttonsmall" />
</s:form></td>
</tr>
</s:iterator>
</tbody>
</table>
</div>
The scenario is as follows:
I entered some values in search.jsp. I submitted the form, and accordingly some results got loaded into the mainContent <div>. Since form was submitted using Struts 2 jQuery plugin submit , the URL remains the same and hence browser back button doesn't work. If I want to go back, how can I do that.
I read about some hash technique but , I am not able to apply it to this.
In the header tag of Struts2 jQuery use ajaxhistory attribute. Setting this attribute to true enabled browser history for Ajax requests. For details see wiki of header tag.

Displaying Java Property in JSP

I have a class with a property called title and I have a getter/setter that gets and sets the property. If the property is P I need to print the word "Peer" on the page, and if it's T I need to print "Team" on the page. Can I do this in a JSP without using a scriplets? I tried using
<jsp:getProperty name="value" class"classname" />
but from there I have no idea how to use a conditional in a JSP. Please help.
Use JSTL, as #CoolBeans says. It would look something like this:
In the servlet,
// where myBean is an instance of the class with [get|set]Title
request.setAttribute("myFoo", myBean);
Then, in the JSP,
<c:choose>
<c:when test="${myBean.title eq 'P'}">Peer</c:when>
<c:when test="${myBean.title eq 'T'}">Team</c:when>
</c:choose>
If you're not familiar with JSTL, I'd recommend reading through the JSP section of the Java EE 5 Tutorial, or picking up a copy of Head First Servlets and JSP (it's quite good).
You should use JSTL. Here is an example:
<%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:if test="${yourClass.p eq 'P'}">PEER</c:if>
I used properties to set and get data from the user, by creating a java class handler and use a "useBean"... Here is some code I generated to fix my problem... hope it helps..
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login and Do Action</title>
</head>
<% // java code
%>
<body>
<jsp:useBean id="myBean" scope="session" class="org.mypackage.IFPWAFCAD.NameHandler" />
<jsp:setProperty name="myBean" property="name"/>
<jsp:setProperty name="myBean" property="screenName"/>
<jsp:setProperty name="myBean" property="username"/>
<jsp:setProperty name="myBean" property="password" />
<h1>Hello <jsp:getProperty name="myBean" property="screenName" />! Ready to Login and perform Action</h1>
<form method="post" action="DBConnection">
<table border="0">
<thead>
<tr>
<th>
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Table:</td>
<td><input type="radio" name="tableName" value="product"/>Produce
<<input type="radio" name="tableName" value="customer" />Customer
<input type="radio" name="tableName" value="actor" checked="checked" />Actor</td>
</tr>
<tr>
<td>Action:</td>
<td>
<select name="action" value="0">
<option value="0">Choose a Action...</option>
<option value="create">Create</option>
<option value="read">Read</option>
<option value="update">Update</option>
<option value="delete">Delete</option>
<option value="fancy">Fancy Display</option>
<option value="pass">Pass to JSP File</option>
</select>
</td>
</tr>
<tr>
<td>Record ID:</td>
<td><input type="text" name="tid" size="3"/></td>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<input type="text" name="firstname" size="30"/>
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<input type="text" name="lastname" size="30"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="hidden" name="name" value="<jsp:getProperty name="myBean" property="name" />" />
<input type="hidden" name="username" value="<jsp:getProperty name="myBean" property="username" />" />
<input type="hidden" name="screenName" value="<jsp:getProperty name="myBean" property="screenName" />" />
<input type="hidden" name="password" value="<jsp:getProperty name="myBean" property="password" />" />
</td>
</tr>
</tbody>
</table>
<input type="submit" value="Login" />
<input type="reset" name="clear" value="Clear" />
</form>
</body>

Categories