private static void writeFile(String stringToWrite, String pathResponse) {
FileWriter fw = null;
BufferedWriter out = null;
try {
fw = new FileWriter(pathResponse,true);
out = new BufferedWriter(fw);
out.write(stringToWrite);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
out.close();
fw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Monday, February 13, 2012
Read a File Using JAVA
public class ReadFile {
public static void main(String args[]){
String pathRequest = "SupportFiles\\Test\\"+apiName+".txt";
readFile(pathRequest);
}
private static void readFile(String pathRequest) {
FileInputStream fis = null;
DataInputStream in = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
fis = new FileInputStream(pathRequest);
in = new DataInputStream(fis);
isr = new InputStreamReader(in);
br = new BufferedReader(isr);
String strLine;
while ((strLine = br.readLine()) != null){
System.out.println (strLine);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
br.close();
isr.close();
in.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String args[]){
String pathRequest = "SupportFiles\\Test\\"+apiName+".txt";
readFile(pathRequest);
}
private static void readFile(String pathRequest) {
FileInputStream fis = null;
DataInputStream in = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
fis = new FileInputStream(pathRequest);
in = new DataInputStream(fis);
isr = new InputStreamReader(in);
br = new BufferedReader(isr);
String strLine;
while ((strLine = br.readLine()) != null){
System.out.println (strLine);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
br.close();
isr.close();
in.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Sunday, February 12, 2012
SQL JOINS
- JOIN: Return rows when there is at least one match in both tables
- LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
- RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
- FULL JOIN: Return rows when there is a match in one of the tables
Friday, February 3, 2012
Exception Handling in JSTL
Using jstl tag <c:catch> we can capture the exceptions occuring in jsp pages
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
<title>Error Handling Example</title>
</head>
<body>
<c:catch var ="catchException">
The exception will be thrown inside the catch:<br>
<% int x = 5/0;%>
</c:catch>
<c:if test = "${catchException!=null}">
The exception is : ${catchException}<br><br>
There is an exception: ${catchException.message}<br>
</c:if>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
<title>Error Handling Example</title>
</head>
<body>
<c:catch var ="catchException">
The exception will be thrown inside the catch:<br>
<% int x = 5/0;%>
</c:catch>
<c:if test = "${catchException!=null}">
The exception is : ${catchException}<br><br>
There is an exception: ${catchException.message}<br>
</c:if>
</body>
</html>
Using JSTL in Web Application
- Create Web Application.
- Add standard.jar and jstl.jar in lib folder under WEB-INF.
- Add a taglib directive to the jsp page on which you want to use JSTL as
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> - The page is now configured to use JSTL library
Example is:-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Enter credentials to Login</title>
</head>
<body>
Values is <c:out value="${param.userType}" /> here
</body>
</html>
How to add style sheet to an html page
How to add style sheet to an html page
- Create a css file say index.css and add style to it
body{@import url('https://fonts.googleapis.com/css?family=Tangerine&display=swap');body{font-family: 'Tangerine', serif;font-size: 48px;}
- In the header section of your html page, add the reference to the above css file path
<!DOCTYPE html><html lang="en"><header><link rel="stylesheet" href="index.css"></header><body><div>your page content</div></body>
- The style defined in the index.css file will be available on the page
Subscribe to:
Posts (Atom)
SpringBoot Application Event Listeners
When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...
-
1. Create a tld file inside WEB-INF folder having declaration of the custom function as below <?xml version="1.0" encoding=...
-
JOIN : Return rows when there is at least one match in both tables LEFT JOIN : Return all rows from the left table, even if there are no m...