Simple Q&A

John Doe ·

1164 Views

Q : Where can I download JSTL taglibs? i.e. jstl.jar and standard.jar

A : If you're running a Servlet 2.5 compatible container and the web.xml is declared as at least Servlet 2.5, then you should be able to use the new JSTL 1.2 instead. Note that JSTL 1.2 does not require a standard.jar.

Q : The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

A : Add a runtime first and select project properties. Then check the server name from the 'Runtimes' tab

Q : Remove html tags from string using java

A : 

String noHTMLString = htmlString.replaceAll("\\<.*?>","");

Using Jsoup

public static String html2text(String html) {
    return Jsoup.parse(html).text();
}

https://stackoverflow.com/questions/4432560/remove-html-tags-from-string-using-java

Q : JSPX

A : https://jspx-bay.sourceforge.net/

Q : Apache Jakarta

A : http://archive.apache.org/dist/jakarta/

Q : Prevent download attempts of videos in a video server

A : Silverlight might be an idea to start with.

Q : mp3 header information reader not working

A : import org.farng.mp3.MP3File; you need to call mp3file.seekMP3Frame(); before attempting to retrieve bitrate, this method will read the file headers including the bitrate. or use http://www.jthink.net/jaudiotagger/examples_id3.jsp

Q : How to get the message in a custom error page (Tomcat)?

A :

<c:out value="${requestScope['javax.servlet.error.message']}"/>

javax.servlet.error.status_code    java.lang.Integer
javax.servlet.error.exception_type java.lang.Class
javax.servlet.error.message        java.lang.String
javax.servlet.error.exception      java.lang.Throwable
javax.servlet.error.request_uri    java.lang.String
javax.servlet.error.servlet_name   java.lang.String

* <c:catch> Tag

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<html>
   <head>
      <title><c:catch> Tag Example</title>
   </head>

   <body>
      <c:catch var ="catchException">
         <% int x = 5/0;%>
      </c:catch>

      <c:if test = "${catchException != null}">
         <p>The exception is : ${catchException} <br />
         There is an exception: ${catchException.message}</p>
      </c:if>
   </body>
</html>

Q : Get current action in jsp - struts2

A : 

<s:url forceAddSchemeHostAndPort="true" includeParams="all"/>

Q : Oracle date to Java date

A : little h for "Hour in am/pm (1-12)" and H for "Hour in day (0-23)" see here: SimpleDateFormat

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = dateFormat.parse("2011-08-19 06:11:03.0");

Q : How to get previous URL?

A : 

HttpServletRequest.getHeader("Referer");

Q : [JSP] 파일 다운로드창에서 한글깨짐 방지?

A :

response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "utf-8") + ";");