Validate e-mail address with regular expression

/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ All regular expressions start and end with forward slashes to differentiate them from ordinary string expressions. Most regular expressions start matches at the first character ^ and end at the last $. Now we try to match the mailbox Continue reading Validate e-mail address with regular expression

Read The Init-Params Defined In The web.xml

[eg. of web.xml <web-app> <servlet> <servlet-name>ReadInitParams</servlet-name> <servlet-class>com.company.MyServlet</servlet-class> <display-name>Example Servlet</display-name> <init-param> <param-name>emailHost</param-name> <param-value>192.168.1.1</param-value> </init-param> </servlet> </webapp> In Servlet Code: public void init(ServletConfig config) throws ServletException { String emailHost = config.getInitParameter(“emailHost”); } or public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException Continue reading Read The Init-Params Defined In The web.xml

Difference between request.getParameter() and request.getAttribute()

The difference between getAttribute() and getParameter() is that getParameter() will return the value of a parameter that was submitted by an HTML form or that was included in a query string. getAttribute() returns an object that you have set in Continue reading Difference between request.getParameter() and request.getAttribute()

Runtime.getRuntime().exec()

To copy a file, you can use the following command: copy source.txt destination.txt To run this in Java, String[] cmd = {“copy”,”source.txt”,”destination.txt”} Runtime.getRuntime().exec(cmd); This may generate error=2. To fix this, use the complete path of copy.exe eg. C:\Windows\System32\copy.exe

Hibernate gives “No CurrentSessionContext configured” error

If you use Hibernate in a managed environment (with JBoss or some other AS that Hibernate supoorts). Add this line to session-factory section: <property name=”hibernate.current_session_context_class” >jta </property> If you use Hibernate in a non-managed environment (standalone application with JDBC). Add Continue reading Hibernate gives “No CurrentSessionContext configured” error