aspose file tools*
The moose likes JSP and the fly likes How do I Edit values in a jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How do I Edit values in a jsp page" Watch "How do I Edit values in a jsp page" New topic
Author

How do I Edit values in a jsp page

chikku sankar
Greenhorn

Joined: Oct 29, 2012
Posts: 6
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

Joined: May 26, 2003
Posts: 31057
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
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

Joined: Oct 29, 2012
Posts: 6
Ok...I will show you the jsp code I am using to fetch data from file.Here it goes :

%>
chikku sankar
Greenhorn

Joined: Oct 29, 2012
Posts: 6
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

Joined: Oct 29, 2012
Posts: 6
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

Joined: Aug 09, 2012
Posts: 179
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

Programming is about thinking, NOT coding
chikku sankar
Greenhorn

Joined: Oct 29, 2012
Posts: 6
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

Joined: Aug 09, 2012
Posts: 179
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

Joined: Oct 29, 2012
Posts: 6
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

Joined: Jun 06, 2007
Posts: 2718
    
    6

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.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I Edit values in a jsp page