Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Eseguire una servlet

  1. #1
    Utente di HTML.it L'avatar di Ironmax
    Registrato dal
    Dec 2008
    Messaggi
    1,026

    Eseguire una servlet

    Salve.
    Ho copiato questa servlet ed l'ho messa dentro un progetto Dynamic Web Project.
    Solo che è inserita come un package, e volevo capire se è possibile far eseguire questa servlet come se fosse una jsp.
    Ho provato a lanciarla con il comando run on server, ma come risposta ho un errore 404, praticamente non trovata.
    codice:
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import org.apache.jasper.runtime.*;
    import org.apache.jasper.runtime.JspException;
    
    public class Prima_Servlet extends HttpJspBase {
    	static {
    	}
    
    	public Prima_Servlet () {
        }
    
    	private static boolean _jspx_inited = false;
    
    	public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
        }
    
    	public void _jspService(HttpServletRequest request, HttpServletResponse  response)
    	      throws java.io.IOException, ServletException {
    	JspFactory _jspxFactory = null;
    	   PageContext pageContext = null;
    	      HttpSession session = null;
    	     ServletContext application = null;
    	   ServletConfig config = null;
    	   JspWriter out = null;
    	    Object page = this;
    	   String  _value = null;
    	     try {
    		  if (_jspx_inited == false) {
    		  synchronized (this) {
    		       if (_jspx_inited == false) {
     		       _jspx_init();
    			_jspx_inited = true;
    		    }
    		 }
    		  }
     	   _jspxFactory = JspFactory.getDefaultFactory();
    		 response.setContentType("text/html;charset=ISO-8859-1");
     	   pageContext = _jspxFactory.getPageContext(this, request, response,
    			 "", true, 8192, true);
    		 application = pageContext.getServletContext();
    	       config = pageContext.getServletConfig();
    	       session = pageContext.getSession();
    		  out = pageContext.getOut();
    	     // HTML // begin [file="/corso_jsp/lezione1/esempio1.jsp";from=(0,63);to=(7,2)]
    	      out.write(
    		  "\r\n<html>\r\n<head>\r\n  <title>Corso di JSP, Lezione 1, Esempio 1</title>" +
     	     "\r\n</head>\r\n<body>\r\n  <h1>Questa è una pagina JSP!</h1>\r\n"
    		);
    		  // end
    		// begin [file="/corso_jsp/lezione1/esempio1.jsp";from=(7,4);to=(7,60)]
    		 SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); 
    		  // end
    		// HTML // begin [file="/corso_jsp/lezione1/esempio1.jsp";from=(7,62);to=(8,17)]
    		  out.write("\r\n	
    
    Sono le ore ");
    	     // end
     	   // begin [file="/corso_jsp/lezione1/esempio1.jsp";from=(8,20);to=(8,44)]
    	     out.print( sdf.format(new Date()) );
    		 // end
    	       // HTML // begin [file="/corso_jsp/lezione1/esempio1.jsp";from=(8,46);to=(12,0)]
    		 out.write("\r\n</body>\r\n</html>\r\n\r\n");
     	   // end
    	     } catch (Throwable t) {
    	    if (out != null && out.getBufferSize() != 0)
    		    out.clearBuffer();
    	      if (pageContext != null) pageContext.handlePageException(t);
    	      } finally {
    		 if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
    	    }
        }
    }

  2. #2
    la devi inserire nell' web.xml ed eventualmente mapparla su una url a tua scelta (sempre nel web.xml). Leggi un po di documentazione , tutorial e o libri sulla programmazione j2ee, questo tipo di dubbi ti si chiariranno al volo facendolo senza dove ricorrere al forum
    Il centro dell'attenzione non è sempre un buon posto in cui trovarsi

    Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.