/    Sign up×
Community /Pin to ProfileBookmark

Sending session from servlet to form

Hi

I have made a html-form with values that is submitted to a servlet. I then validate the values in the servlet and put them in a HTTP-session. If some values are invalid, I want to redirect the user back to the form with the session-values, and use them to fill in the values that were correct. But i don’t know how to access the values in the session that is sent back to the form. I have tried to send the session from the servlet like this:

request.getSession.setAttribute(“name” request.getParameter(“name”);

//Forward request to input-form
RequestDispatcher disp = this.getservletContext.getRequestDispatcher(“form.htm”);
disp.forward(request, response);

I would really appreciate it if someone could help me with this.

to post a comment
Full-stack Developer

1 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliOct 24.2003 — Is your form created by Servelt ???

if so then its simple you can re creates it with fields popluated.

Otherwise,HTTP does not have any thing to realise that you are sending an Object of type Session for the HTML page to process it.

What you can do is redirect the page to form.html and append the values in

fieldnam=value

pairs and then in the form html use JavaScript to parse the url and fill the values.
×

Success!

Help @runekje spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...