java-ee

How can I make Tomcat pre-compile JSPs on startup?

…衆ロ難τιáo~ 提交于 2019-12-17 10:32:38
问题 We're using both Apache Tomcat 6.0 and Jetty 6 where I work. We mostly use Jetty for testing (it's great for running embedded in JUnit tests) and Tomcat for production. By default, Tomcat compiles JSPs on-the-fly as users request them. But this results in degraded performance for the first hit. It also highlights bizarre bugs in Tomcat's JSP compiler. The Tomcat documentation gives recommendations for pre-compiling JSPs at build time using Ant (and a Maven plugin is also available)... but the

Difference between include and forward mechanism for request dispatching concept?

牧云@^-^@ 提交于 2019-12-17 10:16:13
问题 Forward() : This can be done in two ways by Request & ServeletContext. Forwarding a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. Forward is done at server side, without the client's knowledge. When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container. Simply include:

My ear is not able to find ejb module classes

送分小仙女□ 提交于 2019-12-17 10:14:41
问题 I am new to the EAR. I have developed a web module and a ejb module which are dependent on each other for the functionality. For that I am trying to confiure them in a EAR. I mapped both web and ejb module to EAR and can see application.xml as <display-name>EBS-ear</display-name> <module> <ejb>EBS-ejb.jar</ejb> </module> <module> <web> <web-uri>EBS-web.war</web-uri> <context-root>EBS-web</context-root> </web> </module> </application> But when I try to execute EAR my server throws below

Java EE authentication: how to capture login event?

僤鯓⒐⒋嵵緔 提交于 2019-12-17 09:49:53
问题 Given an authentication mechanism of type FORM defined for a Java web app, how do you capture the login performed event before being redirected to requested resource? Is there any kind of listener where I can put my code to be executed when a user logs in? I feel like defining a filter is not the best solution, as the filter is linked to the resource and would be invoked even when the user is already authenticated and asking for a resource. I'm wondering if there's some class/method triggered

JAX-RS using exception mappers

三世轮回 提交于 2019-12-17 09:25:09
问题 I have read that I can create an implementation of javax.ws.rs.ext.ExceptionMapper that will map a thrown application exception to a Response object. I've created a simple example which throws an exception if the phone length is greater than 20 characters when persisting the object. I am expecting the exception to be mapped to an HTTP 400 (Bad Request) response; however, I am receiving an HTTP 500 (Internal Server Error) with the following exception: java.lang.ClassCastException: com.example

web.xml is missing and <failOnMissingWebXml> is set to true

时间秒杀一切 提交于 2019-12-17 08:04:15
问题 Consider: When I create a simple Maven project in Eclipse I am getting this error: web.xml is missing and <failOnMissingWebXml> is set to true How can I fix this problem? 回答1: You can do it also like this: Right click on Deployment Descriptor in Project Explorer . Select Generate Deployment Descriptor Stub . It will generate WEB-INF folder in src/main/webapp and an web.xml in it. 回答2: This is a maven error. It says that it is expecting a web.xml file in your project because it is a web

web.xml is missing and <failOnMissingWebXml> is set to true

核能气质少年 提交于 2019-12-17 08:04:05
问题 Consider: When I create a simple Maven project in Eclipse I am getting this error: web.xml is missing and <failOnMissingWebXml> is set to true How can I fix this problem? 回答1: You can do it also like this: Right click on Deployment Descriptor in Project Explorer . Select Generate Deployment Descriptor Stub . It will generate WEB-INF folder in src/main/webapp and an web.xml in it. 回答2: This is a maven error. It says that it is expecting a web.xml file in your project because it is a web

JPA Multiple Embedded fields

痞子三分冷 提交于 2019-12-17 07:15:58
问题 Is it possible for a JPA entity class to contain two embedded ( @Embedded ) fields? An example would be: @Entity public class Person { @Embedded public Address home; @Embedded public Address work; } public class Address { public String street; ... } In this case a Person can contain two Address instances - home and work. I'm using JPA with Hibernate's implementation. When I generate the schema using Hibernate Tools, it only embeds one Address . What I'd like is two embedded Address instances,

Is there a way to run a method/class only on Tomcat/Wildfly/Glassfish startup?

匆匆过客 提交于 2019-12-17 07:10:26
问题 I need to remove temp files on Tomcat startup, the pass to a folder which contains temp files is in applicationContext.xml. Is there a way to run a method/class only on Tomcat startup? 回答1: You could write a ServletContextListener which calls your method from the contextInitialized() method. You attach the listener to your webapp in web.xml, e.g. <listener> <listener-class>my.Listener</listener-class> </listener> and package my; public class Listener implements javax.servlet

Queries returning multiple result sets

左心房为你撑大大i 提交于 2019-12-17 06:47:17
问题 I have a MSSQL database and am running the following query: select * from projects; select * from user The above query returns two result sets at once, and I cannot fire both queries separately. How can I handle both the result set at once in a Java class? 回答1: Correct code to process multiple ResultSet s returned by a JDBC statement: PreparedStatement stmt = ...; boolean isResultSet = stmt.execute(); int count = 0; while(true) { if(isResultSet) { rs = stmt.getResultSet(); while(rs.next()) {