Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java and JSP help

Have Programming Question? Ask it here!
 
 
 


Jay Patel
Java and JSP help
0 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved on a file, i have the following code:

<html>    
<head>        
<title>JSP Form</title>        
<style>            
</style>    
</head>    
<body>        

<form action="TestFileHandling.jsp" method="post">            
<fieldset>                
<legend>User Information</legend>                

<label for="question">Question</label> 
<input type="text" name="question" /> <br/>   

<input type="submit" value="submit"> 
</fieldset>        
</form>    

</body>
</html>

The above is a simple form that lets the user enter a question before sending it.

<%@page import="myPackage.FileReaderWriter"%>
<%@page import="java.util.Vector"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01                   
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>


 <%
Vector<String[]> v = new Vector<String[]>();
String[] str1 = {request.getParameter("question")};
v.addElement(str1);


FileReaderWriter.saveVectorToFile(v, "MyTestFile.txt");
%>



<%

Vector<String[]> vec =          FileReaderWriter.readFileToVector     ("MyTestFile.txt");
for (int i = 0; i < vec.size(); i++) 
{
    out.print("|");
    for (int j = 0; j < vec.elementAt(i).length; j++) 
    {
        out.print(vec.elementAt(i)[j] + "|");
    }
%>
<br>
<%
}
%>

</body>
</html>

This part takes the question entered and saves it to a text file and then opens the file to display whatever is inside.

All this is done through the following java code:

package myPackage;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class FileReaderWriter {
public static void saveVectorToFile(Vector<String[]> v, String sFileName)
{
    try
    {
        // Create a new file writer
        FileWriter writer = new FileWriter(sFileName, true);

        // Loop through all the elements of the vector
        for (int i = 0; i < v.size(); i++)
        {
            // Capture the index of the last item of each array
            int lastIndex = v.elementAt(i).length - 1;
            // Loop through all the items of the array, except 
            // the last one.
            for (int j = 0; j < lastIndex; j++)
            {
                // Append the item to the file.
                writer.append(v.elementAt(i)[j]);
                // Append a comma after each item.
                writer.append(',');
            }
            // Append the last item.
            writer.append(v.elementAt(i)[lastIndex]);
            // Append a new line character to the end of the line
            // (i.e. Start new line)
            writer.append('\n');
        }
        // Save and close the file
        writer.flush();
        writer.close();
    }
    // Catch the exception if an Input/Output error occurs
    catch (IOException e)
    {
        e

.printStackTrace(); } }

public static Vector<String[]> readFileToVector(String sFileName) { // Initialise the BufferedReader BufferedReader br = null;

// Create a new Vector. The elements of this Vector are String arrays.
Vector<String[]> v = new Vector<String[]>();
try
{
    // Try to read the file into the buffer
    br = new BufferedReader(new FileReader(sFileName));
    // Initialise a String to save the read line.
    String line = null;

    // Loop to read all the lines
    while ((line = br.readLine()) != null)
    {
        // Convert the each line into an array of Strings using 
        // comma as a separator
        String[] values = line.split(",");

        // Add the String array into the Vector
        v.addElement(values);
    }
}
// Catch the exception if the file does not exist
catch (FileNotFoundException ex)
{
    ex.printStackTrace();
}
// Catch the exception if an Input/Output error occurs
catch (IOException ex)
{
    ex.printStackTrace();
}
// Close the buffer handler
finally
{
    try
    {
        if (br != null)
            br.close();
    } catch (IOException ex)
    {
        ex.printStackTrace();
    }
}
// return the Vector
return v;

}

}

currently the code lets the user enter a question and it will save it to a file, and then open the file.

I need to accomplish the following 
1.  The date and time of each request. You may decide on the display format of the date and time yourself.
2.  The text of each request (i.e. the actual question asked by the user).
3.  The status of the request (either ‚??pending‚?? or ‚??answered‚??). Note that a request changes from ‚??pending‚?? to become ‚??answered‚?? only when you have added the text of your response. The initial status of a request is always therefore ‚??pending‚??.
4.  The text of the reply that you provided in answer and the date and time when the reply was made by you.  
5.  A facility on the website which allows a user to obtain at any time they choose a statistical summary report providing, at that very point in time, from all current and previous requests:
a.  The maximum number of hours that is has taken to reply to a request.
b.  The mean number of hours taken to reply to answered requests. 
c.  The median number of hours taken to reply to answered requests. 
d.  The number of requests that have been answered in total be they current or archived.
e.  The number of currently archived messages.  
6.  A facility available for deleting an entry from the list of current requests.
7.  A facility available for adding to the text of an existing reply in the list of current requests.

Any help is appreciated!


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have been given an assignment where I have to fix existing issues in the tool(created using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Advertisements
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...;title>JSP Form</title> <style> </style>...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java
JSP help
JSP help  Hi i am using jsp,html and mysql. I am displaying one question & their 4 options per page. For that i have one label for question &... do this? Please Help
jsp help
jsp help  Hi i am doing my project in jsp.using netbeans 6 and mysql 5.0. and i managed to complete it. and now its submission time. but am confused... with it. so that my project can run independently in any server. plz help me. am so
jsp help - JSP-Servlet
jsp help  hai friends i am using videos,which will play on my webpage using flowplayer.my doubt is where will i store my videos whether in the database or in another local folder. please help me as soon as possible thanks
jsp help - JSP-Servlet
jsp help  i want to add n remove rows dynamically and also want to add data in database in jsp ....  Hi Friend, Try the following code: 1)table.jsp: Add/Remove dynamic rows in HTML table function
jsp help - JSP-Servlet
jsp help  In below code value got in text box using 'ID' Attribute ... I want to use that value in query to fetch related values in same page...://www.roseindia.net/jsp/comboSelect.shtml Thanks
help on project - JSP-Servlet
help on project  Need help on Java Project
jsp help - JSP-Servlet
jsp help  i got below code for dynamically add n delete row... but in my table there are 17 colum in 1 row..i want to add whole row with 17 cloum.. so which changes are required??? 1)table.jsp: Add/Remove dynamic
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
Help With Java...
Help With Java...  Write a java program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2
Help on JSP - JDBC
Help on JSP  Sir I am makeing a project name Online reservation and Enquiry system. I had completed the front end design with the help of html,delete and search the database from the html file with the help of JSP.  hi
java help!
java help!   I need help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods
help in java
help in java   Rational Numbers Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber
Help on JSP and JDBC - JDBC
Help on JSP and JDBC  Retrieve data from Database in JSP and JDBC...;hi friend, jsp only for view , we should use for presentation don t combine databse code and jsp, it is not good approach,use separate class
help in java
help in java  Write an application that prompt the user to enter a number to use as an array size, and then attempt to declare an array using the entered size. Java generates a NegativeArraySizeException if wou attempt to create
java help?
java help?  Write a program, where you first ask values to an array with 6 integer values and then count the sum and average of the values in methods (send in the array & return the counted value to the main program). Print
java help
java help   Write a Java program that does the following: 1.Creates a grading program based on the Baker College grading standard. You will need to look up the current grade standard. You may use only the letter grades without
java help
java help  How to Open CSV Files in a Microsoft Excel Application Using Java Code with example pgm
help for java
help for java  1.convert the following Pseudo code to java if/else structure if student?s grade is greater than or equal to 90 Print ?A? else if student?s grade is greater than or equal to 80 Print ?B? else
sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out
sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out  sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out.I want to have a through knowledge
sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out
sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out  sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out.I want to have a through knowledge
sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out
sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out  sir/mam i want to have knowledge on live projects of java/jsp/servlets.Can you plz help me out.I want to have a through knowledge
help in java
help in java  3.Flights Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities
help in java
help in java  Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consist of a number, followed by an operator, followed
help in java
help in java  The factorial of a nonnegative integer n is written n! (pronounced √Ę‚?¨Ň? n factorial√Ę‚?¨¬?) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1 (for n
help in java
help in java  Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter
help in java
help in java  Gross And Dozens Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you
help in java
help in java  Shopping cart Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use
help in java
help in java   Team Roster Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all... or help me on this pleas.. 7. Gross And Dozens Design and implement a class
please help in jsp - JSP-Servlet
please help in jsp  i have two Jsp's pages. on main.jsp have some... data. here some data of Jsp's. main.jsp... please help.  Hi Friend, Try
java help
java help  1) build class(es) for the dresses, choose (dress ID, color, price, designer)( link lists) 2) construct the driver class by establishing two separate objects for each sister 3) let them both to enter the dresses
java help
java help  Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber for representing such numbers
help in java
help in java  Create a class named Order that performs order processing of a single item. The class has five instance variables (fields) : customer name, customer number, quantity ordered, unit price, and total price. Define
help in java
help in java  Temperature Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have
help in java
help in java  Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number
help in java
help in java  Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter
help in java
help in java  Define a class named Money whose objects represent amounts of U.S. money. The class will have two instance variables of type int for the dollars and cents in the amount of money. Include a constructor with two
Advertisements
 

 

 

DMCA.com