How to get parameter name in case of spring security? - java

I want to retrieve the parameters sent through the form login.jsp in the controller..but I am getting the error-"Request parameter is not present". My code for login.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="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Security</title>
</head>
<body>
<center>
<h1>Welcome to Spring Security Learning</h1>
<c:if test="${not empty SPRING_SECURITY_LAST_EXCEPTION}">
<font color="red">
Your login attempt was not successful due to <br/><br/>
<c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.
</font>
</c:if>
<div style="text-align: center; padding: 30px; border: 1px solid; width: 250px;">
<form method="post"
action='j_spring_security_check'>
<table>
<tr>
<td colspan="2" style="color: red">${message}</td>
</tr>
<tr>
<td>User Name:</td>
<td><input type="text" name="j_username" id="uname"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="j_password" /></td>
</tr>
<tr>
<td colspan="1"><input type="submit" value="Login" /></td>
<td colspan="1"><input name="reset" type="reset" /></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
The code for controller is as follows:-
#RequestMapping("/search")
public ModelAndView search(HttpSession session2,#RequestParam("j_username") String name) {
session2.setAttribute("name", name);
Session session=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();
String hql = "SELECT E.firstName FROM User E";
Query query = session.createQuery(hql);
List results = query.list();
//System.out.println(results.get(1).getClass().getFields());
HashMap model = new HashMap();
model.put("users", results);
return new ModelAndView("search", model);
}
Please help..thanx in advance..

Related

Passing parameters between two JSP in spring mvc

I have a problem transferring data between two jsp
There are two controllers in which the first one accepts the input data, second generate lines with using this params
First controllers group receives two params
#RequestMapping(value = "/create", method = RequestMethod.POST)
public String ProjectSizePost(
#RequestParam("countSprints") Integer countSprints,
#RequestParam("countWorkers") Integer countWorkers) {
BigInteger a = BigInteger.valueOf(countSprints);
return "project/project_size";
}
#RequestMapping(value = "/create", method = RequestMethod.GET)
public String projectSizeGet() {
return "project/project_size";
}
And his jsp
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Size</title>
</head>
<body>
<%--<c:forEach var="inputLine" begin="1" end="4">
<td><input type="text" name="projectManagerId" size="70" value={count} ></td><br>
</c:forEach>--%>
<form action="/project/show_size" method="post" name="/project/show_size"
commandName="projectSizeForm">
<tr>
<td>Count of sprints:</td>
<td><input type="text" name="countSprints" size="70" value = ${countSprints} ></td>
</tr> <br>
<tr>
<td>Count of workers:</td>
<td><input type="text" name="countWorkers" size="70" value = ${countWorkers} ></td>
</tr>
<tr>
<input type="submit" value="Next page"/></td>
</tr>
</form>
</body>
</html>
Second controller and jsp must take params from first jsp
#RequestMapping(value = "/create", method = RequestMethod.POST)
public String createProject(
#RequestParam("projectId") Integer id,
#RequestParam("name") String name,
#RequestParam("startDate") String startDate,
#RequestParam("endDate") String endDate,
#RequestParam("projectStatus") OCStatus projectStatus,
#RequestParam("projectManagerId") Integer projectManagerId) {
MapperDateConverter mdc = new MapperDateConverter();
*//*Project project = new Project.ProjectBuilder()
.projectId(BigInteger.valueOf(id))
.name(name)
.startDate(mdc.convertStringToDate(startDate))
.endDate(mdc.convertStringToDate(endDate))
.build();
project.setProjectStatus(projectStatus);
project.setProjectManagerId(BigInteger.valueOf(projectManagerId));*//*
//projectDao.createProject(project);
return "project/create";
}
And second jsp:
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title>
</head>
<body>
<div align="center">
<form action="/project/create" method="post" name="/project/create"
commandName="projectForm">
<table border="0">
<tr>
<h2>CreateProject</h2></td>
</tr>
<tr>
<td>Project Id:</td>
<td><input type="text" name="projectId" size="70" value = ${projectId} ></td>
</tr>
<tr>
<td>Project Name:</td>
<td><input type="text" name="name" size="70" value = ${projectName} ></td>
</tr>
<tr>
<td>StartDate (mm/dd/yyyy):</td>
<td><input type="text" name="startDate" size="70" value = ${startDate} ></td>
</tr>
<tr>
<td>EndDate (mm/dd/yyyy):</td>
<td><input type="text" name="endDate" size="70" value = ${endDate} ></td>
</tr>
<tr>
<td>Status:</td>
<td><input type="text" name="projectStatus" size="70" value = ${status} ></td>
</tr>
<tr>
<td>Project Manager:</td>
<td><input type="text" name="projectManagerId" size="70" value = ${pmId} ></td>
</tr>
<tr>
<td>Count of sprints</td>
<td><input type="text" name="countSprints" size="70" value = ${countSprints} ></td>
</tr>
<tr>
<td>Count of sprints</td>
<td><input type="text" name="countWorkers" size="70" value = ${countWorkers} ></td>
</tr>
<tr>
<input type="submit" value="Create"/></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Params countSprints and countWorkers

Change html with servlet to jsp

I'm having a bit of trouble with changing html pages to jsp with corresponding changes to the servlet. Usually I have not had an issue with this, but I am now trying to access the database and display tables.
Firstly, the html, corresponding servlet and dao which all works fine.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Bids</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<img src="Images/AllBids_Logo.gif" width="295" height="42">
<form action="controller" method="POST">
<table width="494" height="63" border="1">
<tr>
<td width="70" height="28" bgcolor="#CCCCCC">
<select name="Bidders" >
<option value="NULL">--Select a Bidder--</option>
<option value="M100">Anne Deems</option>
<option value="M200">Joe Black</option>
<option value="M300">Henry Brown</option>
<option value="M400">Sam Pink</option>
<option value="M500">Eva Blue</option>
<option value="M600">George Grey</option>
<option value="M700">James Green</option>
<option value="M800">Sally Orange</option>
</select>
</td>
<td width="150" bgcolor="#CCCCCC">
<select name="Items" >
<option value="NULL">--Select An Item to Bid--</option>
<option value="P100">Acer Pentium 5 Laptop</option>
<option value="P200">Canon Inkjet Printer</option>
<option value="P300">Pioneer Blue Ray Recorder</option>
<option value="P400">20 cm ViewSonic LCD Color Monitor</option>
</select>
</td>
</tr>
<tr bgcolor="#999999">
<td height="27" >
<input type="submit" name="Submit" value="Submit Bid">
</td>
<td bgcolor="#CCCCCC">
<input type="hidden" name="action" value="bid">
Enter Your Bid <input type="text" name="bidValue" size="10">
</td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>View Bids</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<img src="Images/AllBids_Logo.gif" width="295" height="42" alt="Logo">
<form action="controller" method="POST">
<table width="494" height="63" border="1">
<tr>
<td height="28" bgcolor="#CCCCCC">
<select name="Items" size="1">
<option value="NULL">--Select An Item to View Bids--</option>
<option value="P100">Acer Pentium 5 Laptop</option>
<option value="P200">Canon Inkjet Printer</option>
<option value="P300">Pioneer Blue Ray Recorder</option>
<option value="P400">20 cm ViewSonic LCD Color Monitor</option>
</select>
<input type="submit" name="Submit" value="Display Bids">
</td>
</tr>
<tr bgcolor="#999999">
<td height="27">
<input name="action" type="hidden" id="action" value="viewBids">
</td>
</tr>
</table>
</form>
</body>
</html>
This is the part of the servlet used, TableFormatter is a class located within a jar file in the Libraries package.
else if(action.equals("bid")){
AuctionDAO dao = new AuctionDAO(ds);
String itemID = request.getParameter("Items");
String bidderID = request.getParameter("Bidders");
double bidAmount = Double.parseDouble(request.getParameter("bidValue"));
try{
boolean bidRecorded = dao.regBid(itemID,bidderID,bidAmount);
if(bidRecorded){
out.println(formatPage("Your Bid for " + bidAmount + " was recorded"));
}
else {
out.println(formatPage("Your Bid could not be registered"));
}
}catch(Exception ex){
out.println(ex.getMessage());
}// end catch
}// end if
else if(action.equals("viewBids")){
// AuctionDAO dao = new AuctionDAO(ds);
String itemID = request.getParameter("Items");
try{
ResultSet rs = dao.viewBids(itemID);
out.print(TableFormatter.getData(rs));
}catch(Exception ex){
out.print(ex.getMessage());
}// end catch
}// end if
private String formatPage(String message){
StringBuffer output = new StringBuffer();
output.append("<html><head><title>Auction Admin</title></head><body>");
output.append("<h1>" + message + "</h1>");
output.append("</body>");
output.append("</body></html>");
return output.toString();
}
and then, the dao
public boolean regBid(String itemId, String bidderId, double amount)throws SQLException{
int recsInserted = 0;
regBidQuery();
regBidPS.setString(1, bidderId);
regBidPS.setString(2,itemId );
regBidPS.setDouble(3, amount);
recsInserted = regBidPS.executeUpdate();
if(recsInserted == 1){
return true;
}
else {
return false;
}
}
private void regBidQuery()throws SQLException{
regBidPS = con.prepareStatement("INSERT INTO USER1.TBids " +
"VALUES(?,?,?)");
}
Now, All of this works perfectly fine. My jsp pages even work with the new servlet code, but I can't seem to get how to access the TableFormatter class or the regBids() method.
Jsp's:
<%#page import="beans.Member"%>
<%#page import="java.util.List"%>
<%#page import="beans.Item"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bids</title>
</head>
<body>
<img src="Images/AllBids_Logo.gif" width="295" height="42">
<form action="Controller" method="POST">
<table border="1">
<tbody>
<tr>
<td>
<select name="members">
<option value="NULL" selected="true">-- Select A Member --</option>
<% List<Member> members = (List<Member>) session.getAttribute("members");
for (Member member : members){ %>
<option value=<%= member.getMemberId()%> > <%= member.getMemberName()%></option>
<% } //end for %>
</select>
</td>
<td>
<select name="items">
<option value="NULL" selected="true">-- Select An Item To View Bids --</option>
<% List<Item> items = (List<Item>) session.getAttribute("items");
for (Item item : items){ %>
<option value=<%= item.getItemId()%> > <%= item.getItemName()%></option>
<% } //end for %>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit Bid"/>
</td>
<td>
Enter Your Bid <input type="text" name="bidValue" size="10">
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="action" value="bid_view"/>
</form>
</body>
</html>
<%#page import="java.util.List"%>
<%#page import="beans.Item"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>View Bids</title>
</head>
<body>
<img src="Images/AllBids_Logo.gif" width="295" height="42" alt="Logo">
<form action="Controller" method="POST">
<table border="1">
<tbody>
<tr>
<td>
<select name="items">
<option value="NULL" selected="true">-- Select An Item To View Bids --</option>
<% List<Item> items = (List<Item>) session.getAttribute("items");
for (Item item : items){ %>
<option value=<%= item.getItemId()%> > <%= item.getItemName()%></option>
<% } //end for %>
</select>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<input type="submit" value="Display Bids"/>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="action" value="viewbids_view"/>
</form>
</body>
</html>
And this is how I am now running the servlet code - as you can see, the code I have generates the same content as the original html pages, it's just accessing the db and displaying the table and messages that I can't figure out.
if(action.equals("viewbids_view")) {
HttpSession session = request.getSession();
session.setAttribute("items", dao.getItems());
response.sendRedirect("ItemBids.jsp");
}
else if(action.equals("bid_view")) {
HttpSession session = request.getSession();
session.setAttribute("items", dao.getItems());
session.setAttribute("members", dao.getMembers());
response.sendRedirect("Bids.jsp");
}
I'm pretty sure this is the problem, but where do I look to resolve the issue?

Drop down list is not getting displayed with spring mvc and jsp

I have an application where in a JSP page i am displaying a drop down list but i am getting an exception in my code.
public class ExpenseCreationBean {
private String color;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
Controller Class:-
#RequestMapping(value = "/addDetails", method = RequestMethod.GET)
public String getExpenseEntryPage(Model model) {
ExpenseCreationBean expenseCreationBean = new ExpenseCreationBean();
model.addAttribute("expenseCreationBean", expenseCreationBean);
List<String> coloursList = new ArrayList<String>();
coloursList.add("red");
coloursList.add("green");
coloursList.add("yellow");
coloursList.add("pink");
coloursList.add("blue");
model.addAttribute("colours", coloursList);
System.out.println("I was here!!");
return "addDetails";
}
addDetails.jsp Page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
<title>Add Details</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function() {
$("#datepicker").datepicker({
showOn : "button",
buttonImage : "images/calendar.png",
buttonImageOnly : true,
buttonText : "Select date"
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h1>Expense Entry Details</h1>
<form:form method="post" action="savedata" modelAttribute="expenseCreationBean">
<table border="6px" cellspacing="10px" cellpadding="10px">
<tr>
<td>Date Of Purchase: <input type="text" id="datepicker"
name="date_of_purchase"></td>
<td>Item Name:<input type="text" name="description"></td>
<td>Please select:</td>
<td><form:select path="color">
<form:option value="" label="...." />
<form:options items="${colours}" />
</form:select>
</td>
<td>Paid By: <select name="paid_by"></td>
<td>Amount Paid:<input type="text" name="total_price"
id="total_price"></td>
<td>Quantity:<input type="text" name="quantity_purchased"></td>
<td>Unit:<input type="text" name="unit"></td>
</tr>
<tr>
<tr>
<tr>
<tr>
<td>Exclude:</td>
<td><input TYPE="checkbox" name="exclude">
</tr>
<tr>
<td>Comments:<textarea rows="3" cols="25" name="comments"></textarea>
</td>
</tr>
<tr>
            
<td><input type="submit" value="Save" align="middle"></td>
</table>
</form:form>
</body>
</html>
I am getting the below exception :-
javax.servlet.jsp.JspException: Type [java.lang.String] is not valid for option items
org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:143)
org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:157)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
It is just a Spring MVC Web application where i am trying to display the drow down list pre-populated with the colors data.
Any help is highly appreciated.
I added the below line on teh top of addDetails.jsp file and it worked:-
Try to add into Map, instead of ArrayList.
Map<String,String> coloursList = new HashMap<String,String>();
coloursList.put("R","red");
coloursList.put("R","green");
coloursList.put("Y","yellow");
coloursList.put("P","pink");

multiple errors while executing a jsp project

I wrote a jsp project, tried to execute it. I got this error:
listType cannot be resolved to a variable
So I added this lines to my jsp file:
<%#page import="java.util.List"%>
<%#page import="java.util.ArrayList"%>
But it didn't fix the problem. How can I fix it?
There is one more error like this:
The method StudentDetails() is undefined for the type
MangeUser Student.jsp
Here is Student.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import="com.junos.users.MangeUser"%>
<%-- <%# page import="com.junos.userdetails.UserEntityDetails"%> --%>
<%#include file="menu.jsp" %>
<%#page language="java" import="java.util.*,java.io.*,java.sql.*"%>
<%!int skillLevel_id=0;%>
<jsp:useBean id="Student" class="com.junos.users.MangeUser" />
<jsp:setProperty name="Student" property="*" />
<!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> Users </title>
<link href="<c:url value="/resources/data-tables/css/jquery.dataTables.css" />"
rel="stylesheet" type="text/css" />
<script src="<c:url value="/resources/data-tables/js/jquery.dataTables.js" />"type="text/javascript"></script>
<link href="<c:url value="/resources/bootstrap-select/css/bootstrap-select.min.css" />"
rel="stylesheet" type="text/css" />
<script src="<c:url value="/resources/bootstrap-select/js/bootstrap-select.min.js" />"></script>
<style type="text/css">
.bootstrap-select:not([class*="col-"]):not([class*="form-control"]):not(.input-group-btn) {
width: 218px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
var table = $('#usrTable').DataTable();
$('#UserDiv').hide();
$('#tblsDiv').hide();
$('#challenegrDescriptionDiv , #Image ').hide();
$('#addUser').click(function(){
$('#UserDiv').show();
$('#usrTbl').hide();
});
$('.cncl').click(function(){
$('#usrTbl').show();
$('#UserDiv').hide();
});
});
var roleValue = function(){
var val = $('#userRole_id option:selected').text();
if(val == "WAITER"){
$('#tblsDiv').show();
}else{
$('#tblsDiv').hide();
}
if(val == "CHALLENGER"){
$('#usrnmDiv , #passDiv , #cnfrmPassDiv').hide();
}else{
$('#usrnmDiv , #passDiv , #cnfrmPassDiv').show();
}
if(val == "CHALLENGER"){
$(' #Image , #description').show();
$('#challenegrDescriptionDiv , #Image ').show();
}else{
$(' #Image , #description').hide();
$('#challenegrDescriptionDiv , #Image ').hide();
}
}
</script>
<script type="text/javascript">
function PreviewImage() {
alert("PreviewImage");
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("profileImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("imagePreview").src = oFREvent.target.result;
};
};
</script>
<script type="text/javascript">
//getting value of radio button
$(document).ready(function(){
$("input[type='radio']").click(function(){
var radioValue = $("input[name='name']:checked").val();
if(radioValue){
alert("Your are a - " + radioValue);
}
window.location='EditList.jsp?radioValue='+radioValue;
});
});
</script>
</head>
<body >
<div class="container">
<div class="row-fluid">
<div id="UserDiv" class="col-md-8 col-md-offset-2">
<div class="well well-sm">
</div>
</div>
</div>
</div>
<div id="usrTbl" class="col-md-10 col-md-offset-1">
<div class="btn-group" style= "margin-bottom: 10px;">
<button id="addUser" class="btn btn-success" style="margin-left: 10px;">
<span class="glyphicon glyphicon-plus-sign"></span>
</button>
<button class="btn" style="background-color: #9933CC; color: white;margin-left: 10px;">
<span class="glyphicon glyphicon-edit"></span>
</button>
<button class="btn btn-danger" style="margin-left: 10px;">
<span class="glyphicon glyphicon-trash"></span>
</button>
</div>
<table id="usrTable" class="display text-center table-bordered table-striped" cellspacing="0" width="100%">
<thead>
<tr>
<th class="text-center">First Name</th>
<th class="text-center">Last Name</th>
<th class="text-center">User Name</th>
<th class="text-center">Password</th>
<th class="text-center">Mobile Number</th>
<th class="text-center">Email Id</th>
<th class="text-center">Challenger Description</th>
</tr>
</thead>
<tbody>
<%
List<MangeUser> userList= Student.StudentDetails();
System.out.println("userList size: " + userList.size());
pageContext.setAttribute("Users", userList);
%>
<c:forEach items="${Users}" var="user">
<tr>
<td><c:out value="${user.firstName}"/></td>
<td><c:out value="${user.lastName}"/></td>
<td><c:out value="${user.username}"/></td>
<td><c:out value="${user.password}"/></td>
<td><c:out value="${user.mobileNumber}"/></td>
<td><c:out value="${user.emailID}"/></td>
<td><c:out value="${user.challengerDescription}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
<%#include file="footer.jsp" %>
</div>
</body>
</html>
How can I fix those 2 errors?

How to populate a hidden HTML table with the result from the database?

I have a JSP called create-account.jsp which collects a customer's details and sends the data to a Servlet. The Servlet inserts the customer's data into the database, queries the database add sets the results as request scoped attributes and the dispatches to create-account.jsp(same jsp). Now the inserted details must appear in a hidden html table in the jsp. How do I do it? Can any one help?
create-account.jsp
<!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>Create New Account</title>
<style>
a {
text-decoration: none;
}
body {
border-color: azure;
}
</style>
</head>
<body>
<p align="right">Hi, ${sessionScope.user.userName} logout</p>
<h2 align="center">Create New Account</h2>
<form action="${pageContext.request.contextPath}/create.do" method="post">
<table border="1" align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>DOB:(yyyy-mm-dd)</td>
<td><input type="text" name="dob"></td>
</tr>
<tr>
<td>Balance:</td>
<td><input type="text" name="balance"></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Create" name="create">
</td>
</tr>
</table>
</form>
<p align="center" style="display: none">${requestScope.result} has been successfully inserted into the table</p>
<table id="hiddenTable" style="display: none" border="1">
<tr>
<td>
</td>
</tr>
</table>
</body>
</html>
Use
style="visibility: hidden;"
or
style="display:none;"
to hide the table.
for more info have a look at below links
CSS Display and Visibility
Show/Hide div javascript
How to show the result in table?
sample code:
Servlet:
public class Model{
private String name;
private String dob;
private double balance;
// getter and setter
}
...
List<Model> list = new ArrayList<Model>();
//add the data in list
request.setAttribute("list",list);
JSP:
<c:if test="${not empty list}">
<c:forEach var="ob" items="${list}">
<tr>
<td><c:out value="${ob.name}"/></td>
<td><c:out value="${ob.dob}"/></td>
<td><c:out value="${ob.balance}"/></td>
</tr>
</c:forEach>
</c:if>
For complete code have a look at jsp iterate over list

Categories