Search code examples
javajspstrutselscriptlet

access struts bean properties in scriptlet


I've a struts form bean which have several properties and based on those properties I need to create a string url.

e.g., My bean name is formBean and some properties are name, email, mobile and so on.

And the url will contain these form properties as query parameters. For this I've been trying using scriptlet as:

<%! String url = "http://somewebsite.com/request.jsp?param1=" + {accessing formBean.name} %>
<a href="<%= url %>">URL</a>

But the problem I'm facing is to access the bean properties in scriptlet as both can not be used in same context.
What could be the better approach for same? Suggestions are also appreciated.


Solution

  • try using the below code:

    <a href="http://somewebsite.com/request.jsp?name=${formBean.name}&mobile=${formBean.mobile}">URL</a>