Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting into a javabean.  RSS feed

Johnny Woosh
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,
Im supposed to convert this into a java bean. This bean is to be used in conjuction with a JSP page. problem is, i cant seem to convert it. I have to provide getters and setters for certain fields is it? I know i have to declare a package, but im not sure even though ive read thru Any help or guidance will be appreciated thankz.

"java bean"

import java.util.ArrayList;
import javax.sql.*;
class FileIO3 {
/* Main method */
public static void main(String[] args) throws IOException { --> i have to remove this?
FileReader file = new FileReader("limss_h_limss.ord");
BufferedReader fileInput = new BufferedReader(file);
String text;
ArrayList words = new ArrayList();
double text2;
ArrayList numbers = new ArrayList();

String line = "" ;
while((line = fileInput.readLine())!=null){
String[] parts = line.split("=") ;
words.add(parts[0]) ; //add string part
numbers.add(parts[1]) ; //add float part
System.out.println(words); //test output

"JSP page"

<title>Insertion of data</title>
<p> </p>
<p><b>To insert your data into our database, please fill in the required fields below. </b></p>
<p> </p>
<form name="form1" method="POST" action="">
<p>Subject ID:
<input type="text" name="textfield">
<input type="text" name="textfield2">
<p align="left">
<input type="submit" name="Submit" value="Insert">
<input type="hidden" name="" value="form1">
<p> </p>
Ben Souther
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, if you're going to post more than a line or two of your code, please wrap it in a set of UBB CODE tags. This preserves your indenting which makes it much easier to read.

A bean must:
  • Have a zero argument constructor (if you don't create any constructors, the zero arg one will automatically be created for you).
  • Expose any fields that need to be accessible outside of the class with setter/getter (or isXxx for boolean's).

  • You don't have to get rid of the main method (in fact I recommend that you leave it in for testing and debugging) but you need to get that core functionality out of it. Just have you main method, instanciate the object, set it's properties, call it's methods, and then read it's properties back.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!