I have a servlet that reads an external HTML file as a String. I want to add a specific button inside this html which then makes reference to one of my EJB.
Therefore I inserted a:
String button=<h:commandButton value="Test" action="#{myBean.buttonMethod()}" />;
BUT this expression is not evaluated in the output of the servlet by:
out.println(thePage);
I do see just the code for the button, but it is not interpreted.
How can I insert such a reference to one of my method within a servlet dynamically?
That’s not HTML code. That’s JSF code. JSF code is supposed to be executed by declaring the tags in a Facelets or JSP file and having it processed by the
FacesServletby invoking its URL. It’s definitely not the webbrowser who understands JSF as you seemed to think. It only understands HTML.It’s unclear what the concrete functional requirement and why you’re attempting to mix JSF and Servlets this way (I can’t for life imagine a sensible real world reason for this), but assuming that you’ve a plain HTML
<form>which submits to a particular servlet, then one of the ways is to just write normal HTML code instead (which is also what JSF ultimately produces).In the servlet behind that particular
<form action>, do something like