• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I Edit values in a jsp page

 
chikku sankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp page that reads from a property file and displays the data in another jsp page.I want to change the value of the displayed output data directly from the jsp page.
This is the displayed output of my jsp page in table format with 2 columns NAME and VALUE

Name Value

WORD 123
DED 334
EMAIL 232
RDY 23
CHLN 346
RDY1 556
DWNLD 656
GRIV 554
I want to change/edit the column VALUE directly from the page itself .Is there a code for that?If then please help me ASAP
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

YOu can use JavaScript to change information on a page after it has been loaded. Using a library like jQuery will make this easier.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sankar,

could you please post the code that you have tried so far so that me or anyone can help you.

Thanks
 
chikku sankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...I will show you the jsp code I am using to fetch data from file.Here it goes :

%>
 
chikku sankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I change the values in the table (which I showed you in my first post),it should also be reflected in the properties file
 
chikku sankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to edit the values ,but please help me with the jsp code on how to update the changed values back into the properties file.
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well updating a properties file is a heavy weight task of doing IO. You can do it by use a FileOutputStream to open that file and then do the IO job.
For instance check this
 
chikku sankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried the code in the link.But it is having some problem.Can you provide a more clear idea
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chikku sankar wrote:I have tried the code in the link.But it is having some problem.Can you provide a more clear idea


CAn you tell us what you tried and what was the problem
 
chikku sankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code i m using :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="javax.servlet.ServletContext,itdpoc.FetchProperties,java.io.*,java.util.*"%>
<!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>Configured Properties</title>
</head>
<script type="text/javascript">
function update(){

}

</script>
<table border="1">
<tr>
<th align=left>Property Name</th>
<th align=left>Property Value</th>
</tr>
<%
ServletContext context=getServletContext();
InputStream inStream=context.getResourceAsStream("/WEB-INF/ans_itd.properties");
Properties pr = new Properties();
pr.load(inStream);
Enumeration en = pr.keys();
while (en.hasMoreElements()) {%>
<tr>
<%String key=(String)en.nextElement(); %>
<td><%=key%></td>
<td><input type="input" name="PROPERTY VALUE" value="<%=pr.get(key)%>" onclick="editRecord(<%=pr.get(key)%>);" ></td>
<td><input type=submit value="Submit" onClick="update()"></td>
</tr>
<%}
%>
</table>
<br/>
<input type="button" value="Back" onclick="history.back()">
</body>
</html>


This code allows me to edit values in the output window when I run the code.
But how do I update the new value back in the properties file ?
Do I need to include that update function ?
or can I use something else other than file output stream?
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chikku sankar wrote:
But how do I update the new value back in the properties file ?

See Jeanne's reply above. You need AJAX to do it asynchronously without submitting the entire page all the time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic