I have no idea how to use Java as a preprocessor, but the basic idea is going to be this:
- Use Java to grab the information from POST
- Store this somewhere persistent (in PHP I'd use the session information, and Java would probably have something similar)
- Every time the user visits another page, pull their name from the persistent store and insert it into the sidebar.
If you meant Javascript rather than Java than things will be different (I'm not sure there is a persistent store in Javascript), but I hope this helps. If you were doing it in PHP I'd be able to write a quick script to demonstrate. I still could if you'd like, it might be of some use.
Edit:
I'd add this to the comments, but I wouldn't have the space. Anyway, I wrote the PHP script (spent a good amount of time wondering why I was getting a 500 error, turns out I forgot a close parenthesis). This isn't javascript, but it will hopefully help you write your code since it's the same basic idea. You can find the script in production here. The source:
<?php
session_start(); // Start the session so we can use session variables
if(isset($_POST['first_name'])) // Assume that if the user filled out their first name they filled out everything
{
// Assign values based off the POST values
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['age'] = $_POST['age'];
$_SESSION['loggedin'] = true; // Used to tell if the user's logged in or not
}
$first_name = $_SESSION['first_name']; // Read the first name from session data
$last_name = $_SESSION['last_name']; // Read the last name from session data
$age = $_SESSION['age']; // Read the age from session data
$loggedin = $_SESSION['loggedin'];
if(!$loggedin) // If the user isn't logged in, display the login form
{
?>
<html>
<head>
<title>Test script</title>
</head>
<body>
<form action="test.php" method="post">
First Name: <input type="text" name="first_name" />
Last Name: <input type="text" name="last_name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
<?php
}
else // Otherwise, say hello!
{
echo "Hello, " . $first_name . " " . $last_name . "! You are " . $age . " years old!";
}
?>
</body>
</html>
What this does is it starts a session in PHP and stores the values there. You seem to be familiar with what POST is, so I'll just say that $_POST stores values sent via POST. $_SESSION is the array for session data. Both of these are associative arrays, so they store based off keys rather than locations (i.e. $a['hello'] vs $a[2]). After it starts the session it reads values from POST to session data and then from session data to local variables (not the best way to do things, but it works for a demonstration). Then it shows either the greeting or the login form based on if the user's logged in or not.
This same idea can be applied to Javascript with cookies. I'm really not familiar with Javascript so I don't know how much help just code would be so I'll link you to This tutorial on cookies. The idea is to check the cookie when the page loads, set it if it isn't set, and load the data from it if it is set. It shouldn't be too hard to do, especially if you can use my code to help you along.