I am using a example in a book to build my own program (java server pages) I can not even get the example to run. Is there someone to take a look at the program? (netbeans package)?
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
Please post your code so we can have look. When posting please use code tags [ C O D E ] [/ C O D E] and insert your code between them. Code tags are hidden under hash sign "#"
ceyesuma -4 Posting Pro
/*
* FileBean.java
*
* Created on September 1, 2007, 10:13 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package exampleprojects;
/*
* FileBean.java
*
* Created on August 30, 2007, 6:58 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.io.*;
/**
*
* @author fpcampus
*/
public class FileBean {
private String file;
/** Creates a new instance of FileBean */
public FileBean() {
}
public void setFile(String file){
this.file=file;
}
public void setData(String data){
FileWriter fw= null;
PrintWriter pw= null;
try{
fw= new FileWriter(file, true);
pw= new PrintWriter(fw);
pw.println(data);
pw.flush();
pw.close();
fw.close();
}catch(Exception exc){}
}
public String getData(){
FileReader fr= null;
BufferedReader br= null;
String line=" ";
String tempS=" ";
try{
fr= new FileReader(file);
br= new BufferedReader(fr);
line = br.readLine();
while(line!=null){
tempS= tempS + line + "<br>";
line=br.readLine();
}
}catch(Exception exc){}
return tempS;
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Account information</title>
</head>
<body>
<h2>Account information</h2>
<form action="interface.jsp" method="post">
<select name="topic">
<option value="none">Select a topic
<option value="JSP">Java Server Pages
<option value="Tomcat">Tomcat Server
<option value="Java">Java Programming
</select><br><br>
<input type="submit" name="view" value="View bulletin"><br>
<input type="submit" name="post" value="Post bulletin/">
</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Account information</title>
</head>
workspace/ExampleProjects/build/classes/exampleprojects
<body>
<jsp:useBean id="fileBean" class="exampleprojects.FileBean"/>
<%
String topic =request.getParameter("topic");
String vPath ="exampleprojects/"+topic+".txt";
String filePath=getServletConfig().getServletContext().getRealPath(vPath);
if(topic.equals("none")){
%>
Please Select a topic.
<%}else{%>
<jsp:setProperty name="fileBean" property="file" value="<%= filePath %>"/>
<%
if(request.getParameter("view")!= null){
%>
<jsp:getProperty name="fileBean" property="data"/>
<%}%>
<%
if(request.getParameter("post") != null){
%>
<h2>Account Information</h2>
<form action="interface.jsp" method="post">
<TextArea> name=message cols=25 rows=5></TextArea>
<input type=hidden name=topic value="<%= topic%>"><br>
<input type =submit name=addBulletin value="post bulletin">
</form>
<%>}%>
<% if(request.getParameter("addBulletin") !=null && !request.getParameter("message").equals(" ")){
%>
<h2>Bulletin Saved!</h2>
<jsp:setProperty name="fileBean" property="data" param="message"/>
<jsp:setProperty name="fileBean" property="data" value="----------------------------------"/>
<% } %>
<% } %>
<br><br>
<a href="interface.html">Return to main Page</a>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>James Stephen Howerton Advanced Java</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="images/mm_health_nutr.css" type="text/css" />
<script language="JavaScript" type="text/javascript">
//--------------- LOCALIZEABLE GLOBALS ---------------
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
//--------------- END LOCALIZEABLE ---------------
</script>
<style type="text/css">
<!--
a:link {
color: #009900;
}
a:visited {
color: #999999;
}
a:hover {
color: #009999;
}
a:active {
color: #FF0000;
}
a {
font-size: 14px;
}
.style1 {font-size: 12px}
-->
</style></head>
<body bgcolor="#F4FFE4">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#D5EDB3">
<td width="382" colspan="2" rowspan="2"><img src="images/header1.jpg" alt="advanced java programs." width="382" height="101" /></td>
<td width="378" height="50" id="logo" valign="bottom" align="center" nowrap="nowrap">James Stephen Howerton </td>
<td width="100%"> </td>
</tr>
<tr bgcolor="#D5EDB3">
<td height="51" id="tagline" valign="top" align="center">SLCC Forest Park Fall 2006 </td>
<td width="100%"> </td>
</tr>
<tr>
<td colspan="4" bgcolor="#5C743D"><img src="images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td>
</tr>
<tr>
<td colspan="4" bgcolor="#99CC66" background="images/mm_dashed_line.gif"><img src="images/mm_dashed_line.gif" alt="line decor" width="4" height="3" border="0" /></td>
</tr>
<tr bgcolor="#99CC66">
<td> </td>
<td colspan="3" id="dateformat" height="20">Today Is ::
<script language="JavaScript" type="text/javascript">
document.write(TODAY); </script> </td>
</tr>
<tr>
<td colspan="4" bgcolor="#99CC66" background="images/mm_dashed_line.gif"><img src="images/mm_dashed_line.gif" alt="line decor" width="4" height="3" border="0" /></td>
</tr>
<tr>
<td colspan="4" bgcolor="#5C743D"><img src="images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td>
</tr>
<tr>
<td width="40"> </td>
<td colspan="2" valign="top"> <br />
<br />
<table width="610" border="2" align="center" cellpadding="2" cellspacing="0">
<tr>
<td colspan="7" bgcolor="#00FF00" class="pageName"><div align="center">Completed Programs </div></td>
</tr>
<tr>
<td width="22%" height="110" valign="top"><div align="center"><a href="replacement_prog_1.html">Replacement Program</a> </div></td>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href="Celsius Into Fahrenheit_proj_1.htm">Celsius Into Fahrenheit</a> </div></td>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href="OnlineProduceStand.html">Online Produce Stand </a>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href="guest_book.jsp">Guest Book</a></div></td>
</tr>
<tr>
<td class="detailText" valign="top" nowrap="nowrap"><a href="library_lookup.html"></a>Program one /part one <br /></td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap">Program one/part two <br /></td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap">Program two <br></td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap">Program Three/part one</td>
</tr>
<tr>
<td colspan="7"> </td>
</tr>
<tr>
<td height="110" valign="top"><div align="center"><span class="detailText"><a href="xyz.html">XYZ Company</a></span></div></td>
<td valign="top"> </td>
<td height="110" valign="top"><div align="center"><span class="detailText"><a href="musicMagazineOrderForm.html">Music Magazine Order Form</a></span></div></td>
<td valign="top"> </td>
<td height="110" valign="top"><div align="center"><span class="detailText"><a href="javascript:;">update file</a></span></div></td>
<td valign="top"> </td>
<td height="110" valign="top"><div align="center"><span class="detailText"><a href="quiz.html">Quiz</a></span></div></td>
</tr>
<tr>
<td class="detailText" valign="top" nowrap="nowrap">Program three/part two</td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap">Program four</td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap">Program five</td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap">Program six</td>
</tr>
<tr>
<td width="22%" height="110" valign="top"><div align="center"><a href="dbconnection.jsp"> dbconnection.jsp?</a> </div></td>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href=""></a> </div></td>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href=""> </a>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href=""></a></div></td>
</tr>
<tr>
<td width="22%" height="110" valign="top"><div align="center"><a href="interface.html"> interface.html?</a> </div></td>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href=""></a> </div></td>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href=""> </a>
<td valign="top"> </td>
<td width="22%" height="110" valign="top"><div align="center"><a href=""></a></div></td>
</tr>
<tr>
<td class="detailText" valign="top" nowrap="nowrap">Program seven</td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap"></td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap"></td>
<td> </td>
<td class="detailText" valign="top" nowrap="nowrap"></td>
</tr>
<tr>
<td colspan="7"><div align="center" class="style1"><a href="mailto:ceyesumma@hotmail.com">Contact</a><br />
Revised October 26, 2006 </div></td>
</tr>
</table>
</td>
<td width="100%"> </td>
</tr>
<tr>
<td width="40"> </td>
<td width="342"> </td>
<td width="378"> </td>
<td width="100%"> </td>
</tr>
</table>
</body>
</html>
I have a program I am building but I had to back up to this simple program to try to understand how it should work. Please find inclosed an index.html with a links (interface.html) which should post to interface.jsp that uses file bean. I have to get a working knowledge of writing to a file and systematically go through the file and pull out correct entries. Is it easy to perform this with a simple file writer or should I be working with a random access file? Thank you for your time
ceyesuma -4 Posting Pro
here is a zip file . I used netbeans
This attachment is potentially unsafe to open. It may be an executable that is capable of making changes to your file system, or it may require specific software to open. Use caution and only open this attachment if you are comfortable working with zip files.
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
That is why NetBeans should be used once you learned more about Java and development in Java. NetBeans can be realy confusing...
I found some extra bracklets in your JSP file and here is updated version
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Account information</title>
</head>
<body>
<jsp:useBean id="fileBean" class="exampleprojects.FileBean"/>
<%
String topic =request.getParameter("topic");
String vPath ="exampleprojects/"+topic+".txt";
String filePath=getServletConfig().getServletContext().getRealPath(vPath);
if(topic.equals("none"))
{%>
Please Select a topic.
<%}
else
{%>
<jsp:setProperty name="fileBean" property="file" value="<%= filePath %>"/>
<%
if(request.getParameter("view")!= null)
{%>
<jsp:getProperty name="fileBean" property="data"/>
<%}
if(request.getParameter("post") != null)
{%>
<h2>Account Information</h2>
<form action="interface.jsp" method="post">
<TextArea name=message cols=25 rows=5></TextArea>
<input type=hidden name=topic value="<%= topic%>"><br>
<input type =submit name=addBulletin value="post bulletin">
</form>
<%}
if(request.getParameter("addBulletin") !=null && !request.getParameter("message").equals(""))
{%>
<h2>Bulletin Saved!</h2>
<jsp:setProperty name="fileBean" property="data" param="message"/>
<jsp:setProperty name="fileBean" property="data" value="----------------------------------"/>
<% }
} %>
<br><br>
<a href="interface.html">Return to main Page</a>
</body>
</html>
You will now able to navigate from index.html to interface.hml and interface.jsp. However once you create new bulletin and want to view it, it will not be able to display as your bean is dealilng with FileReader that is supposed to create a txt, but I di dnot have time to get it working.
If you will have some problems to run this, just post bellow
ceyesuma -4 Posting Pro
Thanks I apreciate the help very much. I am trying to get past the basics. This web site will be most helpful
ceyesuma -4 Posting Pro
Here is the real project (netbeans) that I am working. I am sure there are several errors. If some one has time could you make heads or tails of it?
This attachment is potentially unsafe to open. It may be an executable that is capable of making changes to your file system, or it may require specific software to open. Use caution and only open this attachment if you are comfortable working with zip files.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.