Problema lettura textarea da servlet

Giacomo_88

Nuovo Utente
27 Ago 2013
6
0
0
Salve a tutti,
ho una pagina jsp nalla quale devo leggere il contenuto di vari campi textarea e texbox tramite una servlet.Con i textbox normali riesco a leggerli tranquillamente con i vari getParameter con il nome del componente web, ma con i textarea no.
Come posso recuperare il loro contenuto??
Il tutto e' racchiuso in una form con un pulsante submit (metodo post).

Grazie
 

Giacomo_88

Nuovo Utente
27 Ago 2013
6
0
0
Ciao Slyfer,

innanzitutto ti ringrazio per la disponibilità,

ecco qui il codice:

pagina jsp:
Codice:
<%-- 
    Document   : inviomsgincrep
    Created on : 30-set-2013, 14.47.07
    Author     : Giacomo
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="Style/styleInvioMsgincrep.css" />
<title>Invio Messaggio INCREP</title>
</head>

<body bgcolor="CORNFLOWERBLUE">
    <form action="inviaIncrep" method="post"> <!--enctype="multipart/form-data"--> 
    <div id="form">
        <h1>Compila il form sottostante per inviare un messaggio INCREP</h1>
	<label for="dest">DESTINATARIO</label>
        <c:choose>
            <c:when test="${status == CREA_NUOVO || status == INOLTRA}">
                <input type="text" name="dest" id="dest" /> 
            </c:when>
            <c:otherwise>
                 <input type="text" name="dest" id="dest" value ="${msg.pattugliadestinatario}" disabled/>
            </c:otherwise>
        </c:choose>
        <label for="mitt">PATTUGLIA MITTENTE</label>
        <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <input type="text" name="mitt" id="mitt" /> 
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA || status == INOLTRA}">
                          <input type="text" name="mitt" id="mitt" value ="${msg.pattugliamittente}" disabled/>
                    </c:when>
                    <c:otherwise>
                          <input type="text" name="mitt" id="mitt" value ="${msg.pattugliamittente}" />
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
        <label for="oggetto">OGGETTO</label>
        <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <input type="text" name="oggetto" id="oggetto" /> 
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA}">
                          <input type="text" name="oggetto" id="oggetto" value ="${msg.oggetto}" disabled/>
                    </c:when>
                    <c:otherwise>
                          <input type="text" name="oggetto" id="oggetto" value ="${msg.oggetto}" />
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
        <label for="gdotime">GRUPPODATAORARIO</label>
        <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <input type="text" name="gdotime" id="gdotime" /> 
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA }">
                          <input type="text" name="gdotime" id="gdotime" value ="${msg.gdotime}" disabled/>
                    </c:when>
                    <c:otherwise>
                          <input type="text" name="gdotime" id="gdotime" value ="${msg.gdotime}" />
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
       	<label for="posizioneutm">COORDINATE UTM</label>
         <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <input type="text" name="posizioneutm" id="posizioneutm" />
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA }">
                          <input type="text" name="posizioneutm" id="posizioneutm" value ="${msg.posizioneutm}" disabled/>
                    </c:when>
                    <c:otherwise>
                          <input type="text" name="posizioneutm" id="posizioneutm" value ="${msg.posizioneutm}" />
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
        <label for="descrizioneevento">DESCRIZIONE EVENTO</label>
        <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <textarea name="descrizioneevento" id="descrizioneevento" cols="50" rows="20"></textarea>
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA}">
                          <textarea name="descrizioneevento" id="descrizioneevento" cols="50" rows="20" disabled >${msg.descrizioneevento}</textarea> 
                    </c:when>
                    <c:otherwise>
                          <textarea name="descrizioneevento" id="descrizioneevento" cols="50" rows="20" >${msg.descrizioneevento}</textarea> 
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
	<label for="valutazione">VALUTAZIONE</label>
         <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <textarea name="valutazione" id="valutazione" cols="50" rows="20"></textarea>
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA}">
                          <textarea name="valutazione" id="valutazione" cols="50" rows="20" disabled >${msg.valutazione}</textarea> 
                    </c:when>
                    <c:otherwise>
                          <textarea name="valutazione" id="valutazione" cols="50" rows="20" >${msg.valutazione}</textarea> 
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
	<label for="misureintraprese">MISURE INTRAPRESE</label>
         <c:choose>
            <c:when test="${status == CREA_NUOVO}">
                 <textarea name="misureintraprese" id="misureintraprese" cols="50" rows="20"></textarea>
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${status == VISUALIZZA}">
                          <textarea name="misureintraprese" id="misureintraprese" cols="50" rows="20" disabled >${msg.misureintraprese}</textarea> 
                    </c:when>
                    <c:otherwise>
                          <textarea name="misureintraprese" id="misureintraprese" cols="50" rows="20" >${msg.misureintraprese}</textarea> 
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
	
        <c:if test="${status != VISUALIZZA}">
                <label>FILE</label>
                <input type="file"  name="nomeFile" /><br>
                <input type="submit" class="bottone" name="submit" value="Invia" /> <!--id="submit"-->
                <input type="reset" class="bottone"  name="reset" value="Cancella"/> <!--id="reset"-->
        </c:if>
    </div>
</form>

<br>
<ul id="menu">
    <li><a href="messaggiRicevuti?status=0&idMessaggio=0">TORNA A RICEVUTI</a></li>
    <li><a href="logout?">LOGOUT</a></li>
</ul>
</body>
</html>


servlet ControllerServlet.java

Codice:
package controller;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import query_facade.QueryManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import messaggi.MsgIncrep;
import messaggi.MsgTenlines;
import query_facade.QueryManager;
import messaggi.utente;
import static java.lang.System.out;
import java.util.Scanner;
import javax.servlet.ServletContext;
import javax.servlet.http.Part;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import query_facade.SettaggioQueryGetMessaggi;

//import messaggi.ConnettiDatabase;
public class ControllerServlet extends HttpServlet {

    private static final int VISUALIZZA = 1;
    private static final int CREA_NUOVO = 2;
    private static final int RISPONDI = 3;
    private static final int INOLTRA = 4;
    
    
    private final QueryManager queryManager = QueryManager.getQueryManager();
    utente u = new utente();
    String tabella="";
    String queryMessaggiRicevuti="";

   
        
    /**
     *
     * @throws ServletException
     */
    @Override
    public void init() throws ServletException {
    
    }
    public void processRequest(
            HttpServletRequest request,
            HttpServletResponse response)
                throws IOException
    {
        PrintWriter out = response.getWriter();
        ServletContext context = this.getServletContext();

        HttpSession session = request.getSession(true);
        Integer counter = (Integer)context.getAttribute("counter");

        out.print("<html>");
        out.print("<body>");
        out.print("<h2>There are " + counter + " users</h2>");
        out.print("</body>");
        out.print("</html>");
    }

    /**
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override //metodo get non viene utilizzato
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setAttribute("VISUALIZZA", 1);
        request.setAttribute("CREA_NUOVO", 2);
        request.setAttribute("RISPONDI", 3);
        request.setAttribute("INOLTRA", 4);
        request.setAttribute("tabella",tabella);

        String userPath = request.getServletPath();
        String url = "";

       
       
        //voglio inviare un nuovo messaggio increp
        if (userPath.equals("/messaggioIncrep")) {
            
            HttpSession session = request.getSession();
            userPath = "inviomsgincrep";

            int status = Integer.valueOf(request.getParameter("status"));

            switch (status) {
                case VISUALIZZA:
                case RISPONDI: {
                    int idMessaggio = Integer.valueOf(request.getParameter("idMessaggio"));

                    MsgIncrep msg = queryManager.getSingoloMsgIncrepRicevuto(idMessaggio,tabella,u);
                    request.setAttribute("status", VISUALIZZA);
                    request.setAttribute("msg", msg);
                    break;
                }
                case INOLTRA: {
                    int idMessaggio = Integer.valueOf(request.getParameter("idMessaggio"));

                    MsgIncrep msg = queryManager.getSingoloMsgIncrepRicevuto(idMessaggio,tabella,u);
                    request.setAttribute("status", INOLTRA);
                    request.setAttribute("msg", msg);
                    break;
                }
                case CREA_NUOVO: {
                    request.setAttribute("status", CREA_NUOVO);
                    break;
                }
                default: {
                    throw new RuntimeException();
                }
            }

            url = "/WEB-INF/view/" + userPath + ".jsp";

        }
       
        try {
            request.getRequestDispatcher(url).forward(request, response);
        } catch (ServletException | IOException ex) {
            ex.printStackTrace();
        }
    }

    /**
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override // metodo post
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setAttribute("VISUALIZZA", 1);
        request.setAttribute("CREA_NUOVO", 2);
        request.setAttribute("RISPONDI", 3);
        request.setAttribute("INOLTRA", 4);
        request.setAttribute("tabella",tabella);

        String userPath = request.getServletPath();
        String url = "";

       
        if (userPath.equals("/inviaIncrep")) {
            
            HttpSession session = request.getSession();
            MsgIncrep msg = new MsgIncrep();
            System.out.println(request.getParameter("misureintraprese"));
          
            msg.setOggetto(request.getParameter("oggetto"));
            msg.setGdotime(request.getParameter("gdotime"));
            msg.setPosizioneutm(request.getParameter("posizioneutm"));
            msg.setDescrizioneevento(request.getParameter("descrizioneevento"));
            msg.setValutazione(request.getParameter("valutazione"));
            msg.setMisureintraprese(request.getParameter("misureintraprese"));
            
            System.out.println(request.getParameter("misureintraprese"));
            System.out.println(request.getParameter("oggetto"));
            System.out.println(msg.getMisureintraprese());
            System.out.println(msg.getOggetto());
            System.out.println("NON HO PRESO I DATI DAI CAMPI TEXT DI MSGINCREP.JSP");
            boolean inserito = queryManager.inserisciMsgIncrep(msg);
            if(!inserito){
                
                        System.out.println("RECORD NON INSERITO");
                        System.out.println(inserito);
                    
                    }
            else {
                    System.out.println("RECORD INSERITO con successo!!!");
            }
            /*
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                // get access to file that is uploaded from client
                Part p1 = request.getPart("oggetto");
                InputStream is = p1.getInputStream();

                // read filename which is sent as a part
                Part p2 = request.getPart("nomeFile");
                Scanner s = new Scanner(p2.getInputStream());
                String filename = s.nextLine();    // read filename from stream

                // get filename to use on the server
                String outputfile = this.getServletContext().getRealPath(filename);  // get path on the server
                FileOutputStream os = new FileOutputStream(outputfile);

                // write bytes taken from uploaded file to target file
                int ch = is.read();
                while (ch != -1) {
                    os.write(ch);
                    ch = is.read();
                }
                os.close();
                out.println("<h3>File uploaded successfully!</h3>");
            } catch (Exception ex) {
                out.println("Exception -->" + ex.getMessage());
            } finally {
                out.close();
                    
            }
                    */
        } // end of doPost()

       
        try {
            request.getRequestDispatcher(url).forward(request, response);
        } catch (ServletException | IOException ex) {
            ex.printStackTrace();
        }

    }

}


web.xml
Codice:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <servlet>
        <!--definire una servlet all’interno del Deployment Descriptor-->
        <servlet-name>ControllerServlet</servlet-name>
        <servlet-class>controller.ControllerServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
   
    <servlet-mapping>
        <servlet-name>ControllerServlet</servlet-name>
        <url-pattern>/inviaIncrep</url-pattern>
    </servlet-mapping>
    <!--<multipart-config>
        <location>/tmp</location>
        <max-file-size>20848820</max-file-size>
        <max-request-size>418018841</max-request-size>
        <file-size-threshold>1048576</file-size-threshold>
    </multipart-config>-->
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
   
</web-app>



Grazie ancora
 
Discussioni simili
Autore Titolo Forum Risposte Data
P Problema con lettura filesystem del client da server! Upload multiplo foto. PHP 5
P problema lettura cookie PHP 11
L Problema con lettura dati da selezione multipla in php PHP 8
LaKanka Problema lettura file feed xml PHP 2
E Problema con la lettura di un file di testo Classic ASP 3
F problema php scrittura e lettura file PHP 2
Z problema lettura/scritture file txt PHP 11
I Sto progettando nuovi siti utilizzando bootstrap e devo dire funziona bene, l'unico problema e la maschera -moz- HTML e CSS 0
K Problema form update PHP 2
O problema con dvr dahua xvr5116 IP Cam e Videosorveglianza 0
S Problema nel ciclare un json Javascript 0
G Problema con Xampp Web Server 1
andrea barletta Problema con miniature comandi Photoshop 0
I problema con alice Posta Elettronica 0
K Problema Inner join PHP 1
F firefox problema http Linux e Software 0
N Problema con position absolute e overflow HTML e CSS 4
E Problema jquery Success jQuery 2
L Problema con inner join PHP 11
K [php] Problema con inner join PHP 4
E problema selezione sfumata Photoshop 2
K [PHP] Problema con variabili concatenate. PHP 1
A Problema filtro fluidifica Photoshop Photoshop 1
H Problema Bordi Scontorno Photoshop 1
O problema con query PHP 4
R Problema installazione Realtek WiFi USB rtl8821 Reti LAN e Wireless 0
I problema con 2 account Posta Elettronica 1
L problema collegamento file css con html HTML e CSS 1
Y Problema percorso file in rete PHP 1
N Problema SEO "L'URL non si trova su Google" SEO e Posizionamento 4
E Problema accesso a file con app sviluppata con MIT APP INVENTOR 2 Sviluppo app per Android 0
P Problema acquisizione clienti Webdesign e Grafica 1
F NetBeans problema creazione progetto Java Windows e Software 0
M Problema con Try Catch PHP 0
C problema seo + cerco esperto SEO e Posizionamento 11
Sergio Unia Problema con gli eventi del mouse su una data table: Javascript 2
T PROBLEMA CON SESSIONI PHP 3
A Problema, non so, di scale() o transform, oppure altro? HTML e CSS 0
T ALTRO PROBLEMA CON ARRAY PHP PHP 1
R problema con else PHP 0
T PROBLEMA CON ARRAY PHP 8
L problema con query select PHP 2
R Problema query con ricerca id numerico PHP 2
F Problema con risposta PHP 0
S problema con recupero dati tabella mysql PHP 2
Z Problema con il mio tp-l i nk Reti LAN e Wireless 1
I PROBLEMA: Sostituzione sito XAMPP E-Commerce 0
T problema data 30/11/-1 PHP 0
L Problema RAM con Tomcat 8 Apache 0
napuleone problema con sort e asort PHP 4

Discussioni simili