Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:35:27+00:00 2026-05-29T23:35:27+00:00

<html> <head> <title>JSP Form</title> <style> </style> </head> <body> <form action=TestFileHandling.jsp method=post> <fieldset> <legend>User Information</legend>

  • 0
<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;
}


}

The part thats really confusing me is how would I edit this so that after a question is posted on the form, the date and time of the post is automatically added to the beginning of each question.

To do this I know I would first need to import the date utility in java and then put something like this on my form page:

<%!Date startTime = new Date();%>

Once I get to that part I start thinking to myself, how would I pass the information inside startTime onto my java file that handles the appending of the vector?

Something else I tried already was simply putting Date startTime = new Date(); into the java file and then using a simple code like writer.append(startTime); so that the date inside startTime is appended along with the question entered, however this didn’t work at all and just gave me a error. In the end this led me to believe that the best way to do this is to just use the scriplet:

<%!Date startTime = new Date();%>

How exactly would I pass the information held in startTime onto my java code so that it can be appended inside the same element of the vector that the question entered was saved to? Thanks for any help or advice.

EDIT: can someone also please explain why writer.append(startTime); doesn’t work? It seems like it should work perfectly fine… Hopefully understanding whats wrong will bring me a step closer to figuring this out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:35:29+00:00Added an answer on May 29, 2026 at 11:35 pm

    Just add it to String[] before adding to Vector<String[]>:

    String[] str1 = { startTime.toString(), request.getParameter("question") };
    

    If you need a different date format, look at SimpleDateFormat.


    Unrelated to the concrete problem, perhaps you’re dealing with a decade old application, but do you realize that this code is full of obsolete APIs and poor practices?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<html> <head> <title>JSP Form</title> <style> </style> </head> <body> <form action="TestFileHandling.jsp" method="post"> <fieldset> <legend>User Information</legend>
<html> <head> <title>ADD URL Sources</title> </head> <body> <form action=Test1.jsp method=post> <br><br><select name=source onchange=> <option
I am using this HTML <html> <head> <Title>EBAY Search</title> </head> <script language=JavaScript src=ajaxlib.js></script> <body>
I have the following HTML <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server> <title></title> <style> .box {
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
For example: <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en> <head> <title>title</title> </head> <body> <a href=aaa.asp?id=1> I want
I have a code like this <html> <head>Title <script> function callme() { alert(Hi); document.test.action
I wrote next jsp: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8> <title>JSP Page</title> <link rel=stylesheet
I have created two JSP programs as follows. First One: Addmulti.jsp <html> <head><title>Upload Excel
Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.