puede para org jasperexception jasper getrealpath estado compilar clase java xml jsp java-ee

java - getrealpath - estado http 500 org apache jasper jasperexception no se puede compilar la clase para jsp



¿Por qué getRealPath() devuelve null cuando se implementa con un archivo.war? (10)

Esto resuelve el problema también:

weblogic.xml

<?xml version = ''1.0'' encoding = ''windows-1252''?> <weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"> <container-descriptor> <index-directory-enabled>true</index-directory-enabled> <show-archived-real-path-enabled>true</show-archived-real-path-enabled> </container-descriptor> <virtual-directory-mapping> <local-path>bla.war</local-path> <url-pattern>*</url-pattern> </virtual-directory-mapping> <context-root>bla</context-root>

Esta pregunta ya tiene una respuesta aquí:

getRealPath() devuelve la ruta real en el sistema local, pero devuelve nulo cuando se implementa con un archivo .war .

<%@ page import="java.io.*" %> <%@ page contentType="text/html;charset=ISO-8859-1" %> <% int iLf = 10; char cLf = (char)iLf; String a= application.getResource("/"); //String myfile = application.getRealPath("/")+ "generate.xml"; //String myfile = request.getContextPath()+"generate.xml"; //String myfile = request.getRealPath("/")+"generate.xml"; out.println(myfile); File outputFile = new File(myfile); outputFile.createNewFile(); FileWriter outfile = new FileWriter(outputFile); outfile.write(" <?xml version=''1.0'' encoding=''UTF-8''?> "+cLf); outfile.write(" <playlist version=''1'' xmlns = ''http://xspf.org/ns/0/'' > " +cLf); outfile.write(" <title>My Band Rocks Your Socks</title> "+cLf); outfile.write("<trackList>"+cLf); %> <%! String[] sports; %> <% sports = request.getParameterValues("sports"); out.println("<html><body><h1>hello</h1></body></html>"); if (sports != null) { for (int i = 0; i < sports.length; i++) { // outfile.writeln (sports[i]); String total=sports[i]; String[] sa=total.split("[,]"); // String[] sub=new String(); outfile.write("<track>"+cLf); for (int j=0;j<sa.length;j++) { // outfile.writeln(sa[j]); // outfile.writeln("sa["+j+"]="+sa[j]); if( j == 0) { outfile.write("<location>" + sa[0] +"</location>"+cLf); } else if (j == 1) { outfile.write("<image>" + sa[1] +"</image>"+cLf); } else if( j==2) { outfile.write("<title>" + sa[2] +"</title>"+cLf); } }// end of inner for loop() outfile.write("</track>"+cLf); //outfile.writeln(); }// end of outer for() } //else outfile.writeln ("<b>none<b>"); outfile.write(" </trackList> "+cLf); outfile.write(" </playlist> "+cLf); outfile.close(); %> <object type="application/x-shockwave-flash" width="400" height="170" data="xspf_player.swf?playlist_url=generate.xml"> <param name="movie" value="xspf_player.swf?playlist_url=generate.xml" /> </object>

¿Alguien puede proporcionarme una alternativa para esto? Sería muy útil si también mostraras algún código de muestra.


La siguiente solución funciona bien para mí.

// I am using Struts2 ServletContext sc = (ServletContext) ac.get(StrutsStatics.SERVLET_CONTEXT); fileInputStream = sc.getResourceAsStream("test.xls");

Después de desplegar el archivo war, puedo obtener el archivo de la ruta de contexto.


Lo siguiente soluciona mi problema.

public EHWInit() { String resetRootPath = ""; try{ resetRootPath = this.getClass().getResource("/").getPath(); boolean isWinOS = System.getProperty("os.name").startsWith("Windows"); if( isWinOS ) {resetRootPath = resetRootPath.substring(1, resetRootPath.lastIndexOf("chucec"));} else {resetRootPath = resetRootPath.substring(0, resetRootPath.lastIndexOf("chucec"));} resetRootPath = resetRootPath.replace("%20", " "); System.out.println("EHWInit#75:resetRootPath=" + resetRootPath);

Cuando intenta obtener getRealPath por this.getClass (). GetResource ("/"). GetPath () cuando OS es Windows, entonces puede obtener una cadena como la siguiente:

EHWInit#73:getPath=/C:/Program%20Files%20(x86)/Apache%20Software%20Foundation/Tomcat%208.5/webapps/chucec/WEB-INF/classes/

Por lo tanto, debe hacer algunos trabajos adicionales en la cadena de devolución. Además, si desea obtener getRealPath por solicitud. Puede reemplazar el código de la siguiente manera:

public void resetSystemPath(HttpServletRequest paramHttpServletRequest) { //String str = paramHttpServletRequest.getRealPath("/"); HttpSession session = paramHttpServletRequest.getSession(true); String str = session.getServletContext().getRealPath("/"); System.out.println("getRealPath:"+str);


No creo que sea posible hacer lo que estás tratando de hacer.

Debes usar getResource para leer el archivo xml desde dentro de tu archivo war (esto también funciona sin guerra)

servletContext.getResourceAsStream("/generate.xml")

La barra diagonal principal depende de dónde se almacena generate.xml.


Para empezar, ServletRequest.getRealPath (String path) está en desuso. El reemplazo apropiado es:

ServletContext context = session.getServletContext(); String realContextPath = context.getRealPath(request.getContextPath());

Sin embargo, los documentos API para ServletContext.getRealPath (ruta de cadena) indican:

"Este método devuelve un null si el contenedor de servlets no puede traducir la ruta virtual a una ruta real por algún motivo (como cuando el contenido está disponible desde un archivo .war)".

¡Entonces la API está cumpliendo su contrato! Sin embargo, no todo está perdido, ya que puede cargar un recurso del WAR utilizando el siguiente método, como se define en ServletContext :

ServletContext context = session.getServletContext(); InputStream is = context.getResourceAsStream("generate.xml");


Tenga en cuenta que context.getRealPath() puede devolver un valor nulo cuando hay un problema de permiso de usuario, verifique el servidor web que se ejecuta bajo qué usuario.


Un poco tarde, pero me encontré con esta pregunta cuando tuve este problema en WebLogic. Mi solución fue agregar esto a mi weblogic.xml :

<?xml version=''1.0'' encoding=''UTF-8''?> <weblogic-web-app> <container-descriptor> <show-archived-real-path-enabled>true</show-archived-real-path-enabled> </container-descriptor> </weblogic-web-app>

Encontré esta solución mejor para cuando no desea (o no puede) editar la configuración en el servidor de WebLogic.


Yo también tuve los mismos problemas. Llamar a getRealPath () devuelve nulo cuando se implementa en un servidor independiente. Después de buscar por un tiempo, encontré la solución para esto, no está en el código. Está en la configuración de tu servidor web.

Para mí es Weblogic 10.3, vaya a Inicio - - Configuración - Aplicación web, establezca Archived Real Path Enabled en true. Reinicie el servidor y todo funciona bien.

Espero esta ayuda, Saludos.


si quieres escribir en

utilizar

this.getClass().getResource("/").getPath();

para obtener el camino