#Controller
#RequestMapping(value ="/provider" ,method=RequestMethod.POST)
public String welcome(Model model){
Transaction trans=new Transaction();
ArrayList<Transaction> asd=new ArrayList<Transaction>();
List<Transaction> list=driverService.groupby();
model.addAttribute("list1",list);
return "NewFile";
}
public interface DriverService {
public List<Transaction> groupby();
}
#Service("driverService")
public class DriverServiceImpl implements DriverService{
#Autowired
private DriverDAO driverDAO;
#Override
public List<Transaction> groupby() {
return driverDAO.groupby();
}
}
public interface DriverDAO {
public List<Transaction> groupby();
}
#Repository("driverDAO")
public class DriverDAOImpl implements DriverDAO{
#Autowired
private HibernateTemplate hibernateTemplate;
#SuppressWarnings("unchecked")
#Override
public List<Transaction> groupby() {
String hql="select count(tx.driver.driverid),tx.driver.drivername from Transaction tx group by driver";
return (List<Transaction>)hibernateTemplate.find(hql);
}
}
pojo class
#Entity
#Table(name="driver_registration")
public class DriverDetails {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="driver_id")
private String driverid;
#Column(name="driver_name")
private String drivername;
#OneToMany(mappedBy="driver", cascade = CascadeType.ALL)
private List<Transaction> items;
//setter and getters
}
#Entity
#Table(name="transaction")
public class Transaction {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="transaction_id")
private String transactionid;
#ManyToOne()
#JoinColumn(name="driver_id")
private DriverDetails driver;
//setter and getters
}
jsp page
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# 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>
</body>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="resources/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="resources/css/style.css" rel="stylesheet" type="text/css">
<link href="resources/css/core.css" rel="stylesheet" type="text/css">
<link href="resources/css/themify.css" rel="stylesheet" type="text/css">
<link href="resources/css/dashboard.css" rel="stylesheet" type="text/css">
<title>RajaRatha Provider List</title>
<link href="resources/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
<link href="resources/css/buttons.dataTables.min.css" rel="stylesheet" type="text/css">
<!-- pdf and excel plugins -->
<script type="text/javascript" src="resources/js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="resources/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="resources/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="resources/js/buttons.flash.min.js"></script>
<script type="text/javascript" src="resources/js/pdfmake.min.js"></script>
<script type="text/javascript" src="resources/js/jszip.min.js"></script>
<script type="text/javascript" src="resources/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="resources/js/buttons.print.min.js"></script>
<script type="text/javascript" src="resources/js/vfs_fonts.js"></script>
<script>
$(document).ready(function(){
$('#myTable').DataTable({
'ordering':false,
dom: 'Bfrtip',
buttons:[
{
extend: 'excelHtml5',
title: 'Data export'
},
{
extend: 'pdfHtml5',
title: 'Data export'
},
{
extend: 'csvHtml5',
title: 'Data export'
},
{
extend: 'print',
title: 'Data export'
}
]
});
});
</script>
</head>
<body >
<div class="wrapper">
<div class="preloader" style="display: none;"></div>
<div class="site-overlay"></div>
<!--Navigation panel starts here -->
<%#include file="navigation.jsp" %>
<!--Navigation panel ends here -->
<div class="site-content">
<div class="content-area py-1">
<div class="container-fluid">
<div class="box box-block bg-white">
<h5 class="mb-1">
Providers
<!-- <span class="pull-right">(*personal information hidden in demo)</span> -->
</h5>
<i class="fa fa-plus"></i> Add New Provider
<!-- <table class="table table-striped table-bordered dataTable" id="table-2" id="myTable"> -->
<table class="table table-striped table-bordered dataTable" id="myTable">
<!-- <table id="myTable" class="table table-striped table-bordered dataTable" > -->
<h4 style="color:green">${message}</h4>
<thead>
<tr>
<th>ID</th>
<th>Full Name</th>
<!-- <th>Email</th>
<th>Mobile</th>
<th>Total Requests</th>
<th>Accepted Requests</th>
<th>Cancelled Requests</th> -->
<!-- <th>Status</th>
<th>Ratings</th>
<th>Online</th>
<th>Action</th> -->
</tr>
</thead>
<tbody >
<c:forEach var="list" items="${list1}">
<tr>
<td>${list.driver.driverid}</td>
<td>${trans.driver.drivename}</td>
<%-- <td>${driver.location1.driveremail}</td>
<td>${driver.location1.driverphone}</td>
<td>${noRides}</td>
<td></td>
<td>0</td>
<td>${driver.driverStatus}</td> --%>
<td></td>
<%-- <td><span class="tag tag-success">${driver.location1.driverenabledstatus}</span></td>
<td><a class="btn btn-danger btn-block" href="/RajaRathaDashBoardApp/RajarathaDocumentList">Disable</a>
<td>
<center><a class="btn btn-block label-right" href="/RajaRathaDashBoardApp/RajarathaDocumentList?driver=${driver.location1.driverid}&owner=${driverlocation1.ownerid}">View Details</a>
</center>
<center> <span style='font-size:30px;'>✍</span>
</center>
</td> --%>
</tr>
</c:forEach>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Total Requests</th>
<th>Accepted Requests</th>
<th>Cancelled Requests</th>
<th>Status</th>
<th>Ratings</th>
<th>Online</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<footer class="footer">
<div class="container-fluid">
<!-- <div class="row text-xs-center" > -->
<div class="col-sm-4 text-sm-left mb-0-5 mb-sm-0">
<p>2017-2018. RajaRatha</p>
</div>
<!-- </div> -->
</div>
</footer>
</div>
</div>
</body>
</html>
output:
113:
114: <c:forEach var="list" items="${list1}">
115: <tr>
116: <td>${list.driver.driverid}</td>
117:
118: <<td>${trans.driver.drivename}</td>
119:
Stacktrace:] with root cause
java.lang.NumberFormatException: For input string: "driver"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:144)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:61)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:702)
at org.apache.jsp.view.NewFile_jsp._jspx_meth_c_005fforEach_005f0(NewFile_jsp.java:468)
at org.apache.jsp.view.NewFile_jsp._jspService(NewFile_jsp.java:361)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
I am trying to get individual data from database using group by method in hql but query executed successfully and also it does not display on the respective web page what is the problem in the above code and also how to use group by in Hibernate and Spring Mvc application and also inform what is wrong with the mapping.
1) You query should have the same column ins group by as in the select (excluding the count):
select count(tx.driver.driverid),tx.driver.drivername
from Transaction tx
group by tx.driver.drivername
2) You are trying to perform a projection but you are expecting a List of Transaction. By default the persistence provider will return a List<Object[]> and you will need to extract manually the count column and the drivername column.
3) Alternatively you could use a ResultClass feature -> example
Related
Making a Spring Boot + Thymeleaf application.
I'm trying to pass a list of IDs of the type Integer to my controller based on whether is it checked on a form, in order to delete one or more rows of data from my db table.
However, right now it returns an empty list.
The ID is the primary key of the table.
The controller seems to be working fine because when I manually add an Integer to the list - it can be deleted with no problem.
This is my HTML file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Profile</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link rel="stylesheet" type="text/css" th:href="#{/css/offcanvas.css}">
</head>
<div class="col-9 col-lg-10">
<form th:action="#{/users/profile/history/deldata}" th:object="${logDeleteForm}" method="post">
<!-- <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>-->
<div class="container-fluid text-center">
<div>
<table class="table table-striped w-75">
<thead>
<tr class="bg-dark text-light">
<th>Select</th>
<th>Date</th>
<th>Country</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr th:each="userData: ${userData}">
<td><input type="checkbox"
th:name="ids"
th:value="${userData.id}"/>
</td>
<td th:text="${userData.datetime}"></td>
<td th:text="${userData.country}"></td>
<td th:text="${userData.city}"></td>
</tr>
</tbody>
<input type="submit" value="Delete tests" id="deleteinput"/>
</table>
</div>
</div>
</form>
</div>
<!--</div>-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
My Controller
#PostMapping("/users/profile/history/deldata")
public String deleteUserData(#ModelAttribute("ids") LogDeleteForm logDeleteForm, Model model) {
System.out.println(logDeleteForm.getIds());
List<Integer> ids = logDeleteForm.getIds();
if (ids == null || ids.size() == 0) {
return "redirect:/users/profile/history";
}
for (Integer id : ids) {
userDataService.deleteUserDataById(id);
}
return "redirect:/users/profile/history";
}
And my FormObject classs
public class LogDeleteForm {
private List<Integer> ids = new ArrayList<>();
public LogDeleteForm() {}
public LogDeleteForm(List<Integer> ids) {
this.ids = ids;
}
public List<Integer> getIds() {
return ids;
}
public void setLogIds(List<Integer> logIds) {
this.ids = ids;
}
}
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");
I am trying to export a table from jsp page to pdf. jspdf is also not working for this.
my jsp page goes as below, nothing is happening when I click the button export to pdf
Hi, I am trying to export a table from jsp page to pdf. jspdf is also not working for this.
my jsp page goes as below, nothing is happening when I click the button export to pdf
<!DOCTYPE html>
<%
HeadCountReport hcOb = new HeadCountReport();
String groupName = request.getAttribute("gn").toString();
%>
<%#page import="com.mypay.ApplicationConstants"%>
<%#page import="com.reports.HeadCountReport"%><html dir="ltr" lang="en-US">
<%#taglib uri="http://displaytag.sf.net" prefix="display" %>
<head>
<meta charset="ISO-8859-1">
<script src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/tableExport.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/sprintf.js"></script>
<script type="text/javascript" src="js/jspdf.js"></script>
<script type="text/javascript" src="js/base64.js"></script>
<title>Groupwise Head Count</title>
<meta name="viewport"
content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="css/style.css" media="screen">
<!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
<link rel="stylesheet" href="css/style.responsive.css" media="all">
<link rel="stylesheet" type="text/css" href="css/reports.css"/>
<script type="text/javascript" src="js/sortable.js"></script>
<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
<script type="text/javascript">
function loadTable(){
document.getElementById('tbldiv').width=screen.availWidth;
document.getElementById('tbldiv').height=screen.availHeight;
}
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>
<script type="text/javascript">
function printPDF() {
var printDoc = new jsPDF();
printDoc.fromHTML($('#tblGrp').get(0), 10, 10, {'width': 180});
printDoc.autoPrint();
printDoc.output("dataurlnewwindow"); // this opens a new popup, after this the PDF opens the print window view but there are browser inconsistencies with how this is handled
}
</script>
<script >
function open_win(url_add)
{
window.open(url_add,'welcome','width=300,height=200,menubar=no,status=no,location=no,toolbar=no,scrollbars=no');
}
function myNewWindow(url_add) {
window.open(url_add, "newWindow", "height=200,width=200,status=yes,menubar=no,status=no,location=no,toolbar=no,scrollbars=no")
}
</script>
</head>
<body>
<div id="art-main">
<div class="art-sheet clearfix"><header
class="art-header clearfix"> <%#include file="header.jsp"%>
</header> <nav class="art-nav clearfix"> <%#include file="hmenu.jsp"%>
<jsp:include page="auth.jsp"></jsp:include> </nav>
<div class="art-layout-wrapper clearfix">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content clearfix"><article
class="art-post art-article">
<div class="art-postcontent art-postcontent-0 clearfix">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%">
<div class="clearfix" align="center"> <h2 align="left">Group Break HC Report</h2>
<p> </p>
<input type="button" onclick="tableToExcel('tblGrp', 'Groupwise Break Up')" value="Export to Excel"><input type="button" onClick ="javascript:printPDF();" value="Export to PDF"><br/>
<div id="tblGrp">
<table width="70%" id="tblGrp" align="center" class="sortable">
<tr>
<th width="35" scope="col">SLNo</th>
<th width="89" scope="col">Group</th>
<th width="190" scope="col">Division</th>
<th width="84" scope="col">Staff Type</th>
<th width="107" scope="col">Head Count</th>
</tr>
<%
java.util.List<String[]> listDetail=null;
listDetail = hcOb.getGroupwiseReport(groupName);
Iterator<String[]> itemplid = listDetail.iterator();
int count = 0;
while(itemplid.hasNext()){
String[] sepEmpDet = itemplid.next();
%>
<tr>
<td><%=++count%></td>
<td><%=sepEmpDet[1] %></td>
<td><%=sepEmpDet[3] %></td>
<td><%=sepEmpDet[2] %></td>
<td><%=sepEmpDet[0] %></td>
</tr>
<% }
%>
</table>
</div>
</div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
<%#include file="footer.jsp"%></div>
</div>
</body>
</html>
thanks.
I see the javascript function calls id="tblGrp". However,
<div id="tblGrp">
<table width="70%" id="tblGrp" align="center" class="sortable">
The id appears multiple times, perhaps giving a problem with jspdf. Without more information of the javascript error, Here are a couple of java alternatives.
1) You can build everything using iText.
2) You can design a report in iReport by constructing a jrxml and use the jasper engine for independent pdf exporting/rendering in your application.
3)Here is additional post for alternative to iText.
[Are there any Java PDF creation alternatives to iText?
Without more info of the javascript error, there isn't much to solve here.
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?
am asking this question after some research. Am trying to open a text file located in my local maching with java and jsp. ie when I click a button in jsp it should open the text file for me. Could some one please help me on this.
Hi, Here is my code:
import java.awt.Desktop;
import java.io.File;
public class Start extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
try {
if ((new File("C:\\Debug\\log20.txt")).exists()) {
Process p = Runtime
.getRuntime()
.exec("C:\\Debug\\log20.txt");
p.waitFor();
} else {
System.out.println("File is not exists");
}
System.out.println("Done");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Web.xml:
<servlet>
<servlet-name>LogFile</servlet-name>
<servlet-class>com.abc.def.LogFile</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogFile</servlet-name>
<url-pattern>/logfile</url-pattern>
</servlet-mapping>
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">
<% String status=""; %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>EMC eLicensing</title>
<link rel="stylesheet" type="text/css" href="css/css_ngoe/headerDefault.css" />
<link rel="stylesheet" type="text/css" href="css/css_ngoe/bodyTemplate.css" />
<link rel="stylesheet" type="text/css" href="css/css_ngoe/footer.css" />
<link rel="stylesheet" type="text/css" href="css/css_ngoe/helperClasses.css" />
<link rel="stylesheet" type="text/css" href="css/css_ngoe/railPanel.css" />
<link rel="stylesheet" type="text/css" href="css/css_ngoe/buttons.css" />
</head>
<body>
<!-- Header Start -->
<div class="parentheader">
<div id="header">
<h1>
E
</h1>
<div id="header-text-position">
<div id="header-text"></div>
<br />
</div>
</div>
</div>
<!-- Header End -->
<br>
<br>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<td> </td>
<!-- START CONTENT -->
<td>
<P>
lmgrd options
<BR>
<BR>
<FORM action="start" METHOD="GET">
<table
cellspacing="5" cellpadding="1" border="0">
<tr>
<td>Start/Stop/Reread</td>
<td><input type=submit name=txtSubmit1 id=txtSubmit value="Start" /></td>
</tr>
</table>
</FORM>
<FORM action="stop" METHOD="GET">
<table
cellspacing="5" cellpadding="1" border="0">
<tr>
<td>Start/Stop/Reread</td>
<td><input type=submit name=txtSubmit2 id=txtSubmit value="Stop" /></td>
</tr>
</table>
</FORM>
<FORM action="logfile" METHOD="GET">
<table
cellspacing="5" cellpadding="1" border="0">
<tr>
<td>LOGFILE</td>
<td><input type=submit name=txtSubmit3 id=txtSubmit value=LOG /></td>
</tr>
</table>
</FORM>
<form action="start" method="GET"
enctype="multipart/form-data">
<input type="file" name="file"
value=text />
<input type="submit" />
</form>
<form action="status" method=GET>
<BR>
<BR>
<input type=submit name=Submit id=txtSubmit
value=Status>
</form>
<BR>
status: <%=status %>
<p>
<p>
<p>
</td>
</tr>
</table>
</body>
</html>
You Could you try it like this if you want to browse the file in an external program
Process p = Runtime.getRuntime().exec("C:\\Path\\to\\notepad.exe C:\\Debug\\log20.txt");
And if you want to browse the file in web page you could try the following:
PrintWriter out = res.getWriter();
File file = new File("C:\\Debug\\log20.txt");
if (file.exists()) {
BufferedReader input = new BufferedReader(new FileReader(file));
String line = "";
while ((line = input.readLine()) != null) {
out.println(line);
}
}