2

I'd like to be able to use a java variable as one of the attributes of my HTML tag. For example, I'd like to be able to do this:

<% String questionId = "question" %>
Question: <textarea rows="5" cols="20" name=questionId><%=question %></textarea> 

Where the name attribute would equal "question". The above doesnt work; is there any possible way to do this?

4
  • Sorry, I was a little unclear in my original post -- i just edited it. That is what I currently have and it does not work Commented Mar 10, 2016 at 13:55
  • I believe this would work if your file was a .jsp Commented Mar 10, 2016 at 13:58
  • Your variable is the problem. Please check my answer stackoverflow.com/a/35919004/5678086 Commented Mar 10, 2016 at 14:20
  • Surely there are two ways (1) Java Server Pages, (2) Servelets Commented Mar 10, 2016 at 23:22

2 Answers 2

1

You are not using the variable you set. Means you set questionId and accessing question It has to be fixed as below

<% String questionId = "question" %>
Question: <textarea rows="5" cols="20" name=questionId><%=questionId %></textarea> <br>
Sign up to request clarification or add additional context in comments.

Comments

0

you've forgot the semicolon. try this it must work :

<% String questionId = "question"; %>
Question: <textarea rows="5" cols="20" name=questionId><%=question %> </textarea> <br>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.