i'm new user of jsp and i have this problem.
I post my code

<%@ page language="java" contentType="text/html; charset=UTF-8"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="it.yacme.mystiquexml.mapping.Modello"%>
<%@ page import="it.yacme.mystiquexml.mapping.*" %>
<%@ page import="it.yacme.mystiquexml.business.YacmeRemote"%>
<%@ page import="it.yacme.mystiquexml.presentation.YacmeLocator"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.StringTokenizer"%>

	String jndiURL = null; 
	public void jspInit() {
		jndiURL = (String)getServletConfig().getInitParameter("mystique.server.jndi.url");
	YacmeRemote ccb = null;
	try {
		ccb = YacmeLocator.bind(jndiURL);
	} catch (Exception e) {}

<!--<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  -->
<META HTTP-EQUIV = "pragma" CONTENT="no-cache">
<title>Demo MyStique</title>
<script type="text/javascript" language="JavaScript"> 
       function crea(valore,identificatore){
            nuovo_elemento = document.createElement("div");
            now= valore;
            idArticolo= identificatore;
         function mostraID(){
		<th class="title">Demo MyStiqueXML</th>
<p /><br />
<form action="../pages/maschera.jsp" id="form01" method="post">
<h1>Scegli il tipo di documento che vuoi creare</h1>
<h4>Tipi di documento</h4>
<select id="modelli" name="modelli"
		List articoli = ccb.listArticolo();
        for (Iterator<Articolo> iter = articoli.iterator(); iter.hasNext();) {
        	Articolo articolo = iter.next();
			<option id="<%=articolo.getId_articolo()%>" value="<%=articolo.getDescrizione_articolo()%>"><%=articolo.getNome_articolo()%></option>
 <div class="container" id="container"/>
<br />
<input type="submit" value="Avanti" onClick="mostraID()"/>

I want save me the value of javascript varible "idArticolo" in a jsp variable if it is possible.
if isn't possible how can i do to save me that value to send to the next page?

Thank you

8 Years
Discussion Span
Last Post by ~s.o.s~

Keep a hidden field which would carry the content of the variable idArticolo to the next page which can be then retrieved using the getParameter method of the HttpServletRequest object.

<!-- In your HTML -->
<form action="/someServlet" id="frm"
  <input type="hidden" name="hid" id="hid" value="default">
// In your javascript
function crea(valore,identificatore) {
  // All the other stuff goes here
  var hiddenElem = document.getElementById("hid");
  if(hiddenElem) hiddenElem.value = identificatore;

Just make sure that the crea() function gets called before the form is submitted. You can also assign a default value to the hidden field so that at the server you can determine whether that field was set or not.

Oh and BTW, using scriptlets is bad. There are better ways of dynamically writing out content like JSTL / JSF / some framework which ensure the separation of content / presentation / logic.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.