Erran Morad
Erran Morad

Reputation: 4743

Need help to submit a variable from HTML

I am new to HTML so please bear with me. I want to submit a "variable" or request parameter called "user" as a http request. A server side code will pick up this username and process it. I tried some code and it gives me a blank ouutput:

HTML -

<form method="POST" action = jstl.jsp>
<input type="text" name="user" value="enter username"/>
<button type="submit">Enter</button>
</form>

JSP or server side code -

<c:if test="${user eq 'admin'}">
   You are now a admin.<br>
</c:if>

Please help me.

Upvotes: 0

Views: 52

Answers (1)

Trajan Unger
Trajan Unger

Reputation: 121

Your HTML is good, but in the JSP code you need to precede your user variable with "param".

Like So:

<c:if test="${param.user eq 'admin'}">
   You are now a admin.<br>
</c:if>

You may also benefit from looking at this more comprehensive example:

JSP Form Post Example

Upvotes: 1

Related Questions