Home Answers Viewqa Java-Beginners Java and JSP help

 
 


Jay Patel
Java and JSP help
0 Answer(s)      a year and 3 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!

View Answers









Related Pages:
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
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
help on project - JSP-Servlet
help on project  Need help on Java Project
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
help   how i can send a pitcture on url in java
help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
help
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. any help would be greatly
help
help  Hii.. I have to design one registration page in java that looks like REGISTER USERNAME (here i have to check whether username already exists... to the user) please tell me how could i design that. Please help me asap Thanks a lot
plz help me!!!!!!!! - JSP-Servlet
plz help me!!!!!!!!  i`ve set the environment varaibles for tomcat... html file,.java file and xml file.. under which directory or folder i`ve to save these files.. and also during compilation of java file,class file is created.but
help
help  how can i query for a minimum value of of one of the column in my database through java   Use min to retrieve the minimum value from one column of database table. Suppose you have a table named emp where
help
(); } } SFDV2103 â?? Java Programming Fall, 2012 Term Project... on the percentage of cheating. SFDV2103 â?? Java Programming Fall, 2012 Term... based on the percentage of cheating. please help me
help
this in java then try this: import java.util.*; class SquareNumber { public
help
Java application  public int remainder(int a, int b) { int answer = a % b; System.out.printf("%d % %d = ", a , b); return (answer); } and in my main, int answerRemain
Project realated help - JSP-Servlet
Project realated help   Hi sir i need your assistance em stuck at a point,actualy i am making final year project,i am making OTRS system in java em using sturts ,servlet,i push whole data by layered architecture,sir succesfully
help
. Based on the above scenario, write a complete Java program. Your program should
java servlet help neeed....
java servlet help neeed....  i have little bit miss concept on servlet and jsp....what ever i know always the jsp provoke first then servlet ...like the index .jsp will be called first then from there according to action
Java Programming Help
Java Programming Help  Hello ! I m the student of last year and i need your help to complete my java project. I going to make a site like youtube... with controls .. I Just want to use jsp and applet in my project . Please help me
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
help me on jstl- <c:url> - JSP-Servlet
help me on jstl c:url  what is jstl in java
method returning null on JSP page.Plz HELP!!!
method returning null on JSP page.Plz HELP!!!  public String... to Java, so please help me as it could also because of some silly mistake. Thanks...); return sAddress; } When I am calling this method on the jsp page
method returning null on JSP page.Plz HELP!!!
method returning null on JSP page.Plz HELP!!!  public String... here. I am new to Java, so please help me as it could also because of some silly... on the jsp page it is returning null while the parameter values are successfully
Required help about the concept of JSP page reloading
Required help about the concept of JSP page reloading  Hi, We have one application with Websphere portlet Factory generated JSP as front end, Java in the business layer and finally DB2 as back-end. In certain cases
Required help about the concept of JSP page reloading
Required help about the concept of JSP page reloading  Hi, We have one application with Websphere portlet Factory generated JSP as front end, Java in the business layer and finally DB2 as back-end. In certain cases
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
New to JSP..need help to make & run a JSP program.
New to JSP..need help to make & run a JSP program.  Hi, I have installed Tomcat 5.5 on my system. Plz help me to make a simple JSP program.... Now create a jsp file:'hello.jsp' <%@page language="java"%> <%String st
plz help me - Java Beginners
plz help me  deepak hw can i create a data grid in jsp and also how can i connect to the data base plz help me  to create data grid in jsp use html tables with borders. to connect to data base use scriptlets. ex
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
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
plz help me - Java Beginners
plz help me  Thanks deepak continue response..i face some problem i.... if i m login then display sessionvalid .jsp not display admin page i want display... ParamLoop /jsp/ParamLoopTag
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 needed for Form Validation please help!
Help needed for Form Validation please help!  I have created a page which has login as well as Signup fields. I validated the login part by using jsp... clicking the submit button for sign up it also goes through the jsp code and returns
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
JSP
. For more information, visit the following link: http://www.roseindia.net/help/java... objects in jsp   Implicit objects in jsp are the objects... and are created at the conversion time of a jsp into a servlet. But we can pass
JSP
. For more information, visit the following link: http://www.roseindia.net/help/java/o... objects in jsp   Implicit objects in jsp are the objects... and are created at the conversion time of a jsp into a servlet. But we can pass
JSP
the following link: http://www.roseindia.net/help/java/o/jsp-implicit-objects.shtml  ..., visit the following link: http://www.roseindia.net/help/java/o/jsp-implicit...JSP  what are different implicit objects of jsp   mplicit
Help Me plzzz
Help Me plzzz  org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: D:\prash\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\HelloServlet\org\apache\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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.