简体   繁体   中英

How to include a variable JSP into a HTML label?

I have an JSP file, which is called from a button of a form in a HTML file. In this JSP I get the option selected in a drop-downlist of the form, which is saved into the variable "topic".

In this JSP file I have another button that have to call the Javascript function crearframe(). The parameter have to be the value saved in the variable "topic". How can I do that?

I need to open a different html file when the user press the button depending of the value of the variable "topic". The name of the html file will be "topicValue" + ".html".

Is there any way of doing this?

Thank you very much.

Here is the code.

<script language="javascript">  
function crearframe(htmlFilePath) {
var testframe = document.getElementById("iframe");
testframe.src = htmlFilePath + ".html"; 
}
</script>
</head>

<body>
<table width="100%">
<tr>
<td align="center" valign="top">

<% 
String topic = request.getParameter("opcion");
out.println("<H2>Resultado del análisis sobre " + topic + "</H2>");
%>

<div id="grafica"></div>
<table width="80%">
<tr>
     <td align="center" width="25%">
         <button type="button" name="Analizar1" class="btn btn-primary"  Onclick="crearframe('HaveToBeTheTopicVariable')" >Ver;</button>                

Do in this way using Scriptlets

Onclick="crearframe('<%= topic %>')"

I never suggest you to use Scriptlets instead use JSP Standard Tag Library .

Have a look at How to avoid Java Code in JSP-Files?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM