I want to upload an image file in my project directory folder named Images and store the image name in a database.
The file name has been saved in the database and my image retrieved by the browser properly, but when I check my directory folder named Images it is empty.
My questions is: Where is my file stored and why can't I see the image file in my folder?
This is my Index.jsp file
<%--
Document : index
Created on : Mar 15, 2018, 7:30:15 PM
Author : Lenovo
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="form1" method="post" enctype="multipart/form-data" action="insertimage.jsp">
<p>
<input type="file" name="ImageFile" id="ImageFile" />
</p>
<p>
<input type="submit" name="submit" value="submit" />
</p>
</form>
</body>
</html>
This is my insertimage.jsp file
<%# page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%# page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%# page import="org.apache.commons.fileupload.*"%>
<%# page import="java.util.*, java.io.*" %>
<%# page import="java.util.Iterator"%>
<%# page import="java.util.List"%>
<%# page import="java.io.File"%>
<%# page contentType="text/html;charset=UTF-8" %>
<%# include file="getcon.jsp"%> <!-- to connect a database-->
<%
try
{
String ImageFile="";
String itemName = "";
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart)
{
}
else
{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try
{
items = upload.parseRequest(request);
}
catch (FileUploadException e)
{
e.getMessage();
}
Iterator itr = items.iterator();
while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString();
if(name.equals("ImageFile"))
{
ImageFile=value;
}
}
else
{
try
{
itemName = item.getName();
File savedFile = new File(config.getServletContext().getRealPath("/") + "Images\\" + itemName);
out.println("File Uploaded.." + itemName);
item.write(savedFile);
}
catch (Exception e)
{
out.println("Error" + e.getMessage());
}
}
}
try
{
st.executeUpdate("insert into test(image) values ('" + itemName + "')");
}
catch(Exception el)
{
out.println("Inserting error" + el.getMessage());
}
}
}
catch (Exception e)
{
out.println(e.getMessage());
}
%>
This is my retrieveimage.jsp file
<%# include file="getcon.jsp"%>
<html>
<head>
<title>View Image Page</title>
</head>
<body>
<table width="100%" border="0">
<!-- main content -->
<%
ResultSet rs=null;
try
{
rs = st.executeQuery("select image from test");
while(rs.next())
{
%>
<table width="70%" height="160" border="1" align="center">
<tr>
<!-- Mention Directory where your images has been saved-->
<td><img src="Images/<%=rs.getString("image") %>" width="115" height="128" /></td>
</tr>
</table>
<%
}
}
catch(Exception e)
{
out.print("" + e.getMessage());
}
%>
</table>
</body>
</html>
This is my connection file
<%#page import="java.sql.*" %>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample", "root", "root");
Statement st = con.createStatement();
%>
The following has more chance of working.
File savedFile = new File(config.getServletContext().getRealPath("/Images/" + itemName));
savedFile.getParentFile().mkdirs();
...
Not sure whether the server is also Windows; on other systems path names are case-sensitive (Images with capital i).
You could provide a fixed itemName for testing.
The img tag might need to be:
<img src="/Images/ ...
Related
I created table in database and I have problem with loading picture from that database. Type of data that I used for img is blob, I have good connection with database, all other data is showing on my jsp page but picture wont load. Data type of img is .jpg, dimensions of picture are 250x250 and size about 14.2 kb
CREATE TABLE `akcija` (
`idakcija` int(11) NOT NULL AUTO_INCREMENT,
`naziv` varchar(45) NOT NULL,
`cena` varchar(45) DEFAULT NULL,
`img` blob,
PRIMARY KEY (`idakcija`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
I load data by following insert query:
INSERT INTO `games1`.`akcija` (`naziv`, `cena`,`img`)
VALUES ('TEST','3500', 'C:\\Users\\mlade\\OneDrive\\Desktop\\New Folder (2)\\WebApplication1\\web\\gallery\\ufc4.jpg');
I also tried by right click on field for img and selecting Load Value from File, and then selecting img that I want. And third option that I tried is right click -> open value in editor -> Load image -> Apply -> and Apply on changes
Here is my JSP page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<%#page import="java.sql.DriverManager"%>
<%#page import="java.sql.ResultSet"%>
<%#page import="java.sql.Statement"%>
<%#page import="java.sql.Connection"%>
<%#include file="connection.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%#include file="header.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div class="container">
<img class="img-fluid " src="https://gifcdn.com/1h64r34cpd6coj0dhl.gif" alt="mailtimers.com">
</div>
<table class="table table-sm">
<thead>
<tr>
<th scope="col">Ime igrice</th>
<th scope="col">Cena</th>
<th scope="col">Slika</th>
</tr>
</thead>
<% String id = request.getParameter("id");
Blob img = null;
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
connection = DriverManager.getConnection(connectionUrl + database, userid, password);
statement = connection.createStatement();
String sql = "select * from akcija";
resultSet = statement.executeQuery(sql);
int i = 0;
while (resultSet.next()) {
%>
<tbody>
<tr>
<td><%=resultSet.getString("naziv")%></td>
<td><%=resultSet.getString("Cena")%></td>
<td><img src="<%=resultSet.getBlob("img")%>" width="250" height="250"/></td>
</tr>
</tbody>
<%
i++;
}
} catch (Exception e) {
out.println("Problem");
return;
} finally {
try {
resultSet.close();
statement.close();
connection.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
%>
</table>
</body>
</html>
Data from column naziv and cena is show on jsp page but image wont load. See picture
Picture not loading
Here is screenshots of my project structure. Also screenshots of DB and query that I used to insert data in DB
I have this code to show the images but it not works. doesnt display the image just a little white square, i've been looking for an answer and i cant find , somebody to help me, please.
Show.jsp
<%# page import="java.sql.*" %>
<%# page import='java.io.InputStream' %>
<%# page import='java.io.OutputStream' %>
<%
String login = "root";
String password = "";
String url = "jdbc:mysql://localhost/dbimagenes";
Connection conn = null;
Statement statement = null;
ResultSet rs = null;
int nBytes=0;
%>
<html><style type="text/css">
<!--
body {
background-color: #F5f5f5;
}
-->
</style><body>
<h1>Imagen desde MySQL</h1>
<table>
<tr><td>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection(url, login, password);
statement = conn.createStatement();
rs = statement.executeQuery("SELECT imagen FROM t_imagenes where id='2'");
try{
if(rs.next()){
response.setContentType("image/jpeg");
InputStream is = rs.getBinaryStream(1);
OutputStream aux= response.getOutputStream();
out.println("jajaja");
byte [] buffer = new byte[4096];
for (;;) {
nBytes = is.read(buffer);
if (nBytes == -1)
break;
aux.write(buffer, 0, nBytes);
}
is.close();
aux.flush();
aux.close();
}else{
throw new SQLException("image not found");
}
rs.close();
} catch (SQLException e) { out.println("Imagen no encontrada");}
out.println("no se muestra");
%>
</td></tr></table>
<p> Imagen</p>
PRINCIPAL
</body></html>
My way to save the images into mysql is of this way:
Insert.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#include file="conexion.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Insertar</h1>
<%
String nombre=request.getParameter("txtnombre");
String marca=request.getParameter("txtmarca");
String imagen=request.getParameter("txtimagen");
if(nombre!=null && marca!=null && imagen!=null){
String qry ="insert into t_imagenes(nombre,marca,imagen) values('"+nombre+"','"+marca+"','"+imagen+"')";
sql.executeUpdate(qry);
out.print("Datos Registrados "
+ "<a href='index.jsp'>REGRESAR</a>");
}else{
%>
<form name="frmimagenes" method="post" action="insertar.jsp">
nombre: <input type="text" name="txtnombre"/><br/>
marca: <input type="text" name="txtmarca"/><br/>
imagen: <input type="file" name="txtimagen" value="" size="50" /><br/>
<input type="submit" value="Guardar">
</form>
<%}//else%>
</body>
</html>
you need to use image tag img to display the image in html (i have not test the following code, please adjust it if it has any error)
<%# page import="java.sql.*" %>
<%# page import='java.io.InputStream' %>
<%# page import='java.io.OutputStream' %>
<%# page import='java.io.ByteArrayOutputStream' %>
<%# page import='org.apache.commons.codec.binary.Base64' %>
<%
String login = "root";
String password = "";
String url = "jdbc:mysql://localhost/dbimagenes";
Connection conn = null;
Statement statement = null;
ResultSet rs = null;
int nBytes=0;
%>
<html><style type="text/css">
<!--
body {
background-color: #F5f5f5;
}
-->
</style><body>
<h1>Imagen desde MySQL</h1>
<table>
<tr><td>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, login, password);
statement = conn.createStatement();
rs = statement.executeQuery("SELECT imagen FROM t_imagenes where id='2'");
String url = "data:image/jpeg;base64,";
try{
if(rs.next()){
InputStream is = rs.getBinaryStream(1);
OutputStream aux = new ByteArrayOutputStream();
out.println("jajaja");
byte [] buffer = new byte[4096];
for (;;) {
nBytes = is.read(buffer);
if (nBytes == -1)
break;
aux.write(buffer, 0, nBytes);
}
is.close();
aux.flush();
url += new String(Base64.encodeBase64(aux.toByteArray()));
aux.close();
}else{
throw new SQLException("image not found");
}
rs.close();
} catch (SQLException e) { out.println("Imagen no encontrada");}
out.println("no se muestra");
%>
<img src="<%=url%>" />
</td></tr></table>
<p> Imagen</p>
PRINCIPAL
</body></html>
File upload program is working fine in the local pc when i deploy it online its giving an error, i.e
org.apache.commons.fileupload.FileUploadException: Processing of
multipart/form-data request failed. C:\Program Files (x86)\Apache
Software Foundation\Tomcat 5.0
\upload_4133c5ef_14e0097e702__8000_00000003.tmp (The system cannot
find the path specified)
Below is my code:
<%#page import="java.util.*"%>
<%#page import="java.util.Iterator"%>
<%#page import="java.io.File"%>
<%#page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%#page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%#page import="org.apache.commons.fileupload.*"%>
<%#page import="javax.servlet.ServletConfig"%>
<%#page import="java.sql.*"%>
<%#page import="java.io.*"%>
<%#page import="java.text.*"%>
<%#page import="javax.servlet.Servlet"%>
<%#page import="javax.servlet.ServletException"%>
<%#page import="javax.servlet.http.HttpServlet"%>
<%#page import="com.mmvisa.utils.ConnectionUtils"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Group file Upload</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,700,600,800' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="../css/style.css" type="text/css" />
</head>
<body >
<div id="wrapper">
<div id="header">
<div id="logo">
<img src="../images/logo.jpg" alt="logo" />
</div> <!-- logo -->
<div class="tittle">
<h1> M M VISA-AID CONSULTANCY </h1>
<p>OFFSHORE AGENT OF AUSTRALIAN GOVERNMENT <br />
Department of Immigration & Border Protection</p>
</div> <!-- tittle -->
</div> <!-- header -->
<div class="content" style="min-height:420px;">
<br/>
<center>
<table border="2">
<%
ServletConfig config1 = getServletConfig();
// long useridStr= 0;
String id = "";
long compid = 0;
//List<String> allfileName=new ArrayList<String>();
String allfileName[]=new String[50];
int counterNoOfFiles=0;
int uid = 0;
String year =null;
String invalidFile=null;
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart){
}else{
List items = null;
try{
//FileItemFactory factory = new DiskFileItemFactory();
// ServletFileUpload upload = new ServletFileUpload(factory);
DiskFileUpload upload = new DiskFileUpload();
items = upload.parseRequest(request);
}catch (FileUploadException e){
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()){
////
String name = item.getFieldName();
String value = item.getString();
Long value1 = item.getSize();
System.out.println("dj checking field name-->"+name);
if(name.equals("year")){
year=value;
System.out.println("dj checking field value-->"+year);
}
}else
{
try{
String itemName = item.getName();
//allfileName.add(itemName);
if (item.getSize() > 0){
File uploadedFile = null;
String myFullFileName = item.getName(), myFileName = "",
slashType = (myFullFileName.lastIndexOf("\\") > 0) ? "\\" : "/"; // Windows or UNIX
//System.out.println("in multiple file upload"+slashType);
int startIndex = myFullFileName.lastIndexOf(slashType);
myFileName = myFullFileName.substring(startIndex + 1, myFullFileName.length());
System.out.println("in multiple file upload"+myFileName);
//uploadedFile = new File("C:\\Documents and Settings\\sys\\Desktop\\shastrogyan\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\Hayagriva\\files\\", myFileName);
uploadedFile = new File(getServletContext().getRealPath("\\")+"clientfeedback", myFileName);
//getServletContext().getRealPath("\\")+"uploadfiles\\"
System.out.println("uploaded file "+uploadedFile);
item.write(uploadedFile);
allfileName[counterNoOfFiles]=itemName;
counterNoOfFiles++;
}
}catch (Exception e){
e.printStackTrace();
}
}
}
}
Connection con = null;
PreparedStatement preStat = null;
ResultSet rs = null;
int count=0;
String img=" ";
for(int i=0;i<=counterNoOfFiles;i++)
{
System.out.println("Number of files "+counterNoOfFiles);
img = allfileName[i];
System.out.println("Image name "+img);
}
System.out.println("All Image names "+img);
//Code for Add to database
for(int i=0;i<counterNoOfFiles;i++){
//System.out.println("175"+allfileName.size());
PreparedStatement psmt=null;
try{
con=ConnectionUtils.getConnection();
String sql = "select * from clientfeedback where imagename=?";
System.out.println(sql);
psmt=con.prepareStatement(sql);
psmt.setString(1, allfileName[i].toString());
rs=psmt.executeQuery();
if(rs.next()){
count++;
}else{
if (psmt != null)
psmt.close();
String query = "insert into clientfeedback (imagename,year ) values(?,?)";
System.out.println(query);
psmt=con.prepareStatement(query);
psmt.setString(1, allfileName[i].toString());
psmt.setString(2,year);
psmt.executeUpdate();
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
if (psmt != null)
psmt.close();
} catch (Exception e2) {
}
try {
if (con != null)
con.close();
} catch (Exception e3) {
}
}
}
System.out.println("checking count->"+count);
if(count!=0){
invalidFile="there is "+count+" duplicate file which is not save in database.other file has saved";
}else{
invalidFile="File uploading done successfully";
}
%>
</table>
</center>
<center>
<h3><%=invalidFile %></h3>
</center>
<center>Go to upload page</center>
<br/>
</div> <!-- content -->
<div id="footer" style="margin-top:10px;">
<table>
<tr>
<td width="900">Copyright, All Rights Reserved,MM VISA,2014</td>
<td width="460">Follow us on : <img src="../images/facebook.png" /> <img src="../images/twitter.png" /> <img src="../images/utube.png" /> `enter code here`
<img src="../images/blog1.png" />
<img src="../images/google_plus_icon.png" />
</td>
</tr>
</table>
</div> <!-- footer-->
</div> <!-- wrapper -->
</body>
</html>
Could anyone please help me to solve this problem. Thank you
Apache Commons FileUpload uses the path as set in the java.io.tmpdir system/environment variable as default upload path. You can change the default upload path. Try to see if it solves the problem. Check their docs for configuration details.
I am trying to edit and delete a single record from multiple records.Here below is my sample record displaying on jsp page,
I can edit the record for each row easily using below code,
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# page import="java.util.List" %>
<%# page import="java.util.Iterator" %>
<%#page import="java.sql.ResultSet"%>
<!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>Insert title here</title>
<script src="jquery1.11.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
function editRecording(task_id) {
//alert(task_id)
url = "EditRecord";
window.location="/RTTSchecking/"+url+"?task_id="+task_id;
}
</script>
<table align="center" border="1px" width="80%" >
<thead>
<tr>
<th>User_Id</th>
<th>Class</th>
<th>Subject</th>
<th>Chapter</th>
<th>Planned_Features</th>
<th>Planned_Date</th>
</thead>
<%Iterator itr;%>
<%List data = (List) request.getAttribute("TaskData");
for(itr = data.iterator(); itr.hasNext();)
{
%>
<tr>
<% String s = (String) itr.next();
%>
<td style="background-color: yellow;">
<input type="text" name="tid" value="<%=s %>"></td>
<td><input type="text" name="tid" value="<%=itr.next() %>"></td>
<td><%=itr.next() %></td>
<td><%=itr.next() %></td>
<td><%=itr.next() %></td>
<td><%=itr.next() %></td>
<td><input type="button" value="edit" name="<%=s%>" onclick="editRecording(this.name);"></td>
<td><input type="button" value="delete" name="<%=s%>" onclick="deleteRecording(this.name);"></td>
<% } %>
</tr>
</table>
</body>
</html>
EditREcord(servlet):
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
String a=request.getParameter("task_id");
convty = new Connectivity();
con = convty.setConnection();
st = con.createStatement();
query = "select * from task_table where task_id='"+a+"'";
rset = convty.getResultSet(query, con);
}
catch(Exception e) {
}
finally {
request.setAttribute("EditData", rset);
RequestDispatcher dd= request.getRequestDispatcher("editdata.jsp");
dd.forward(request, response);
out.close();
//out.println(""+tid);
}
}
Above code working fine.But my problem is, i want to delete record based on User_id, Class, Subject, Chapter and Planned_Date so how can i get these values from single row (which want to delete row)?
how to achive this below code?,
<script type="text/javascript">
function deleteRecording(User_id,Class,Subject,Chapter,Date) {
//alert(task_id,Class,Subject,Chapter,Date)
url = "EditRecord";
window.location="/RTTSchecking/"+url+"?user_id="+User_id+"&Tclass="+Class+"&subject="+Subject+"&chapter="+Chapter+"&date="+Date;
</script>
once if i achieved above code then i can easily delete selected single record from multiple rows using below code,
try {
String uid=request.getParameter("user_id");
String class=request.getParameter("Tclass");
String sub=request.getParameter("subject");
String chap=request.getParameter("chapter");
String date=request.getParameter("date");
convty = new Connectivity();
con = convty.setConnection();
st = con.createStatement();
query = "delete from task_table where User_id='"+uid+"' and class='"+class+"' and subject='"+sub+"' and chapter='"+chap+"' and date='"+date+"'";
st.executeUpdate(query);
}
catch(Exception e) {
}
Note : I can do delete records using delete from task_table where User_id='"+uid+"';
but how to do with query = "delete from task_table where User_id='"+uid+"' and class='"+class+"' and subject='"+sub+"' and chapter='"+chap+"' and date='"+date+"'";
I hope someone will help me out.
Once you delete data from database that means it's deleted.
You just need to reload that page again on click of delete.
I hope you've found the solution to your problem by now. But in case you haven't, I ran into the same problem today, and after many experiments, I came up with the following syntax for deleting a row using multiple criteria:
" DELETE FROM table_name WHERE " +
" first_db_field_name = '" + matching_variable_name + "'" +
" and next_db_field_name = '" + next_matching_variable_name + "'" +
" and last_db_field_name = '" + last_matching_variable_name + "'";
This is my jsp page
<%#page import="java.util.List"%>
<%#page import="org.hibernate.cfg.Configuration"%>
<%#page import="org.hibernate.Session"%>
<%#page import="org.hibernate.SessionFactory"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function page_hide_show()
{
for(var i=8;i<22;i++)
{alert(i)
document.getElementsByClassName(i).style.display='none';
}
}
</script>
</head>
<body onload="page_hide_show()">
<%
SessionFactory sessionfactory=null;
Session Listsession=null ;
sessionfactory=new Configuration().configure().buildSessionFactory();
Listsession = sessionfactory.openSession();
String name="";
String age="";
String address="";
String phone_no="";
try
{
int c=0;
if(request.getAttribute("c")!=null)
{
c=Integer.parseInt(request.getAttribute("c").toString());
}
org.hibernate.Query query=Listsession.createQuery("select name,age,address,phone_number from paging order by auto_inc");
query.setFirstResult(c);
query.setMaxResults(10);
List check1 =query.list();
java.util.Iterator on=check1.iterator();
while(on.hasNext())
{
Object oo[]=(Object[])on.next();
name=(String)oo[0].toString().trim();
age=(String)oo[1].toString().trim();
address=(String)oo[2].toString().trim();
phone_no=(String)oo[3].toString().trim();
%>
<div align="center" style="border-bottom:1px solid #ccc "> Name <input type="text" name="text" value="<%=name %> " disabled="disabled">
<br><br>
</div>
<% }
}
catch(Exception ee){
out.print(ee.getMessage());
}
%>
<center> <img src="fgfdg.png"> </center>
<table align="center">
<tr>
<!-- <td>First Page</td> -->
<%
int value_counter=0;
int pagecount=0;
long counters=0;
try{
org.hibernate.Query query=Listsession.createQuery("select count(*) from paging order by auto_inc");
List check1 =query.list();
java.util.Iterator on=check1.iterator();
while(on.hasNext())
{
Object oo=on.next();
counters=((Number)oo).longValue();
}}
catch(Exception e)
{
out.println(e);
}
int count=(int)counters/10;
int Counter_in_int=count*10;
double xyz=Counter_in_int-counters;
if(xyz>=0)
{
for(int i=0;i<count;i++)
{
pagecount++;
%>
<td class="<%=pagecount%>"><%= pagecount%></td>
<% value_counter=value_counter+10;} }
else
{
%>
<%
for(int i=0;i<=count;i++)
{
pagecount++;
%>
<td class="<%=pagecount%>"><a href="Pagecount?c=<%=value_counter %>" ><%= pagecount%></a></td>
<% value_counter=value_counter+10;} }
%>
<!-- <td>Last Page</td> -->
</tr>
</table>
</body>
</html>
So My question is
in the above code I am trying to hide td tags with classname from 8 to 21 but I am unable to do so.I think my javascript function is right.Also when I am giving id to as
< td id="<%=pagecount%>">
I am unable to do so.
kindly tell me how to hide the td's with classname from 8 to 21 in this code.Is my javascript function wrong.
Your problem is that document.getElementsByClassName(something) returns an Array (the plural in elements). That means that you have to have something like this :
var list = document.getElementsByClassName(class_name);
for (i = 0; i < list.length; i++) alert(list[i]);
However, I see you only have one of each class name. In this case, you should just do something like this : document.getElementsByClassName(i)[0].style.display = 'none'.
Hope this was useful :)