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>
Related
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.
My java code is
#RequestMapping(value = "/common_views/view-lecturer-Projects")
public String viewLecturerProjects(HttpServletRequest request, ModelMap map) {
String userId=request.getParameter("userId");
map.put("viewUserProjects", projectService.findProjectByUserId(Long.valueOf(userId)));
System.out.println("=================>Project type= "+projectService.findProjectByUserId(Long.valueOf(userId)).getTypeOfProject());
System.out.println("=================>Project title= "+projectService.findProjectByUserId(Long.valueOf(userId)).getTitleOfProject());
// System.out.println("===============>Project= "+(projectService.findProjectByUserId(Long.valueOf(userId))).get(0).getTitleOfProject());
return "common_views/viewLecturerProjects";
}
the page /common_views/view-lecturer-Projects is
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Index - SIL-Bridge</title>
</head>
<body>
<jsp:include page="/WEB-INF/includes/header.jsp" flush="true" />
<jsp:include page="/WEB-INF/includes/menubar.jsp" flush="false" />
<div class="main main-inner">
<div class="container">
<div class="row">
<div class="span12">
<div class="widget widget-nopad">
<div class="widget-header"><i class="icon-list-alt"></i>
<h3>Home</h3>
</div>
<!-- /widget-header -->
<div class="widget-content">
<form id="view-all-lecturer-project" class="form-horizontal">
<fieldset>
<table id="viewAllLecturersProject" class="table table-striped table-bordered">
<thead>
<tr>
<th>Title of the project</th>
<th>Type of the project</th>
</tr>
</thead>
<tbody>
<c:forEach items="${viewUserProjects}" var="viewUserProject">
<tr>
<td><c:out value="${viewUserProject.titleOfProject}"/></td>
<td><c:out value="${viewUserProject.typeOfProject}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
<br/><br/>
</fieldset>
</form>
</div>
</div>
<!-- /widget -->
</div>
</div>
<!-- /row -->
</div>
<!-- /container -->
</div>
<!-- /main-inner -->
</body>
</html>
In this page values ${viewUserProject.titleOfProject},${viewUserProject.typeOfProject}` not disply in this page but java code print values
Write the following taglib import statement on top of your jsp.
<%# taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
and if you dont have JARSS for JSTL, then download from below URL and put that JAR into your Build Path of project.
http://www.oracle.com/technetwork/java/index-jsp-135995.html
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.
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.
I have jsp loginSuccess.jsp as follows:
<%# 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 prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head />
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<title>Login</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<jsp:include page="menubaruser.jsp"></jsp:include>
<div id="mainContent" >
<div style="width:898px"><br><center>Welcome Mr. <b><s:property value="#session.name"/> </b></center> </div>
<div id="ajaxdiv">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
<br>
<div>
<jsp:include page="userHistoryWidget.jsp"></jsp:include>
</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
This page include many widgets , two of which are search.jsp and userHistoryWidget.jsp. Now when i run this page, everything is fine but the jquery datepicker tag doesn't work.I mean the calender doesn't show up. If i remove the head tag from loginSuccess.jsp, then the datepicker starts working but then the submit button that are coded to send asynchronous request in userHistoryWidget.jsp stops working. They don't respond to clicks.
userHistoryWidget.jsp is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head />
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<div id="searchHeaderHistory">User History</div>
<div class="CSSTableGenerator">
<table>
<colgroup>
<col span="1" style="width: 5%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 8%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 6%;">
<col span="1" style="width: 6%;">
<col span="1" style="width: 17%;">
<col span="1" style="width: 18%;">
</colgroup>
<tr>
<td>Ticket ID</td>
<td>Booking Date</td>
<td>Flight ID</td>
<td>From</td>
<td>To</td>
<td>Total Fare</td>
<td>Net Fare</td>
<td></td>
<td></td>
</tr>
<s:iterator value="ticketsList" var="ticket" status="stat">
<tr>
<td align="center"><s:property value="#ticket.tid" /></td>
<td align="center"><s:property value="#ticket.bookingdate" /></td>
<td align="center"><s:property
value="#ticket.scheduleDetails.flightDetails.fid" /></td>
<s:if test="#ticket.flag==3">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.via" /><br>
<s:property value="#ticket.scheduleDetails.via_dep_date" /> <s:property
value="#ticket.scheduleDetails.via_dep_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==1 ||#ticket.flag==2||#ticket.flag==4">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.source" /><br>
<s:property value="#ticket.scheduleDetails.source_dep_date" /> <s:property
value="#ticket.scheduleDetails.source_dep_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==1 ||#ticket.flag==2||#ticket.flag==3">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.destination" /><br>
<s:property value="#ticket.scheduleDetails.dest_arr_date" /> <s:property
value="#ticket.scheduleDetails.dest_arr_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==4">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.via" /><br>
<s:property value="#ticket.scheduleDetails.via_arr_date" /> <s:property
value="#ticket.scheduleDetails.via_arr_time" />hrs</td>
</s:if>
<td align="center"><s:property value="#ticket.fare" /></td>
<td align="center"><s:property value="#ticket.dealFare" /></td>
<td style="width: 150px" align="center">
<s:url id="getPassengers" value="/getPassengers.action">
<s:param name="Tid" value="#ticket.tid" />
</s:url>
<sj:a id="link_%{#stat.index}" href="%{getPassengers}" targets="ajaxdiv" cssClass="orangebuttonsmall">
View Details
</sj:a>
</td>
<td style="width: 150px" align="center">
<s:a action="cancel" id="button1" style="float:left" cssClass="orangebuttonsmall">Cancel Ticket
<s:param name="Tid" value="#ticket.tid"></s:param>
</s:a>
</td>
</tr>
</s:iterator>
</table>
</div>
</body>
</html>
search.jsp is as follows:
<%# 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 prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head />
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
<title>Search</title>
</head>
<body>
<s:form action="searchFlight" method="post" theme="css_xhtml" cssClass="form1small">
<div class="searchHeadersmall">Search Flight</div>
<div id="searchForm1">
<s:select list="cityList" headerValue="--------Select--------" headerKey="-1"
name="searchFlightDetails.from" label="Leaving From"></s:select>
<s:select list="destlist" headerValue="---------Select-------" headerKey="-1"
name="searchFlightDetails.to" label="Going To"></s:select>
<s:textfield label="Date" name="searchFlightDetails.date_of_travel"
id="datepicker" />
<s:select list="#{'1':'1','2':'2','3':'3','4':'4','5':'5'}"
headerValue="" headerKey="-1"
name="searchFlightDetails.no_of_passengers" label="No of tickets"
style="width:50%; float:left"></s:select>
<div class="inputsmall nobottombordersmall">
Type
<s:radio label="Type" name="searchFlightDetails.nonstop"
list="#{'Y':'NonStop','N':'Normal'}" theme="simple" />
</div>
<div id="submitdivid1">
<sj:submit id="submitsearch" value="Show Flights" targets="mainContent"/>
</div>
</div>
</s:form>
</body>
</html>
Can somebody help me solve this problem? Thanks in advance..
If your intention is just to include the JSPs in other pages to form a complete page, then I suggest remove the repeated part (html, head, body & other similar tags) and contain only specific part, so that the resulting html contains only ONE html, head & body tag.
Secondly, sj plugin requires <sj:head jqueryui="true"/> for the UI components to work. Looking at your code, it appears the the parent page is loginSuccess.jsp & hence, it's <head> should contain this sj:head definition.
Try removing the redundant code and hopefully, it should work.