0

I'm trying the following code in my .jsp file:

<select>
    <%DBHandler db= new DBHandler();%>
    <%db.init();%>
    <%String[] res= db.getExpertise();%>
    <% for(int i=0;i< res.length;i++){ %>

        <option value="<%=res[i]%>"><%=res[i]%></option>
    <%}%>
</select>

But, I don't know how to assign value in a tag using a variable in java code.

1

1 Answer 1

2

Hope this will help your problem;

1. Directives

<%@page language="java" %> 

2. Declarations

<%!    
int radius = 7; 
double pi = 3.1415; 
%>

3. Scriptlets

<%
    String id, name, dob, email, address;

    id = request.getParameter("id");
    name = request.getParameter("name");
    dob = request.getParameter("dob");
    email = request.getParameter("email");
    address = request.getParameter("address");

    sessionEJB.addClient(id, name, dob, email, address);
 %>

4. Expressions

<%!    
double radius = 7; 
double pi = 22/7;    
double area()
{
    return pi*radius*radius;
}    
%>

<html>
  <body>
    Area of circle is <%= area() %>
 </body>
</html>
Sign up to request clarification or add additional context in comments.

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.