Include JSTL dependency with Maven

The dependencies mentioned above is not enough for me(using Tomcat 5.x as servlet container, which doesn’t provide JSTL implementation itself). It just imports the according JSTL interface package into project, and will cause a runtime error in Tomcat. Here is the dependency part used in my project, hopefully can help others out. The hardest part … Read more

How do I send an e-mail in Java?

Here’s my code for doing that: import javax.mail.*; import javax.mail.internet.*; // Set up the SMTP server. java.util.Properties props = new java.util.Properties(); props.put(“mail.smtp.host”, “smtp.myisp.com”); Session session = Session.getDefaultInstance(props, null); // Construct the message String to = “[email protected]”; String from = “[email protected]”; String subject = “Hello”; Message msg = new MimeMessage(session); try { msg.setFrom(new InternetAddress(from)); msg.setRecipient(Message.RecipientType.TO, new … Read more

HttpServlet cannot be resolved to a type …. is this a bug in eclipse? [duplicate]

You have to set the runtime for your web project to the Tomcat installation you are using; you can do it in the “Targeted runtimes” section of the project configuration. In this way you will allow Eclipse to add Tomcat’s Java EE Web Profile jars to the build path. Remember that the HttpServlet class isn’t … Read more

Capture and log the response body [duplicate]

If I understand you correctly, you want to log the response body? As @duffymo pointed out, a Filter is indeed a suitable place for this. You can capture the response body by replacing the passed-in ServletResponse with a HttpServletResponseWrapper implementation which basically replaces the HttpServletResponse#getWriter()/getOutputStream() with an own implementation which copies the response body into … Read more

Eclipse: How do I add the javax.servlet package to a project? [duplicate]

To expound on darioo’s answer with a concrete example. Tomcat 7 installed using homebrew on OS X, using Eclipse: Right click your project folder, select Properties at the bottom of the context menu. Select “Java Build Path” Click Libraries” tab Click “Add Library…” button on right (about halfway down) Select “Server Runtime” click “Next” Select … Read more

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String; That method was added in Servlet 2.5. So this problem can have at least 3 causes: The servlet container does not support Servlet 2.5. The web.xml is not declared conform Servlet 2.5 or newer. The webapp’s runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)