SproutCore is an HTML5 application framework for building responsive, desktop-caliber apps in any modern web browser, without plugins.
yea dil mange more >>
yea dil mange demo>>
Wednesday, March 24, 2010
Thursday, March 18, 2010
ResourceBundle Message Implementation in Spring
Add below in context.xml
beans:bean id="msource" class="org.springframework.context.support.ResourceBundleMessageSource"
beans:property name="basename" value="classpath:mymessages.properties"
-----------------------------------
mymessages.properties
my.user.already.exist={0} already exist!
my.update={0} updated successfully!
my.delete={0} deleted successfully!
---------------------------------------------
Last step just do an autowire in the controller class
@Autowired
@Qualifier("msource")
private MessageSource mymess;
and in the functions use it like below
mymess.getMessage("my.user.already.exist", new Object[] { "Username chandra"}, null)
the Object[] can take multiple params based on the message u want to display
ex:Username {0} cannot be deleted because {1}
--- :)
beans:bean id="msource" class="org.springframework.context.support.ResourceBundleMessageSource"
beans:property name="basename" value="classpath:mymessages.properties"
-----------------------------------
mymessages.properties
my.user.already.exist={0} already exist!
my.update={0} updated successfully!
my.delete={0} deleted successfully!
---------------------------------------------
Last step just do an autowire in the controller class
@Autowired
@Qualifier("msource")
private MessageSource mymess;
and in the functions use it like below
mymess.getMessage("my.user.already.exist", new Object[] { "Username chandra"}, null)
the Object[] can take multiple params based on the message u want to display
ex:Username {0} cannot be deleted because {1}
--- :)
Saturday, March 13, 2010
How to use base64 to add a basic authentication to an HTTP request.
Use the "Authorization", "basic "+encodedpassword like below.
import org.apache.commons.codec.binary.Base64;
String userpasswd = username+":"+password;
String encodedString = new String(Base64.encodeBase64(userpasswd.getBytes()));
....
and in ur httpconnection object add the below
conn.setRequestProperty("Authorization","Basic "+encodedString);
...
URL url = new URL("https://fyi.com");
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Authorization"....
if (conn instanceof HttpsURLConnection)
((HttpsURLConnection) conn).setHostnameVerifier(DNV);
conn.connect();
import org.apache.commons.codec.binary.Base64;
String userpasswd = username+":"+password;
String encodedString = new String(Base64.encodeBase64(userpasswd.getBytes()));
....
and in ur httpconnection object add the below
conn.setRequestProperty("Authorization","Basic "+encodedString);
...
URL url = new URL("https://fyi.com");
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Authorization"....
if (conn instanceof HttpsURLConnection)
((HttpsURLConnection) conn).setHostnameVerifier(DNV);
conn.connect();
how to use "Content-Disposition" for file download via http(s)/ftp server
Content-Disposition Header Field
This is an optional field. Never thought this could save my ass.
It has a wonderful param "filename" thru which we can out the content of the file to be downloaded. If you don't use it, the file will download with the servlet name.
Ex: /fyi/myservlet.do
While downloading the file, the dialog prompts to save file with myservlet.do which is really odd & when ur downloading a zip file the name says "save file myservlet.do"
If you dont understand any (:-) thing above see the below code.
response.setHeader("Content-Disposition", "attachment; filename="+ filename);
URL url = new URL("https://fyi/downloadfile/filename.zip");
conn = (HttpsURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream in = conn.getInputStream();
response.setContentType(conn.getContentType());
response.setContentLength(conn.getContentLength());
response.setHeader("Content-Disposition", "attachment; filename="
+ filename);
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int size = 0;
while ((size = in.read(buf)) >= 0) {
out.write(buf, 0, size);
}
in.close();
out.close();
}
try urself.
to know more about content-disp..
This is an optional field. Never thought this could save my ass.
It has a wonderful param "filename" thru which we can out the content of the file to be downloaded. If you don't use it, the file will download with the servlet name.
Ex: /fyi/myservlet.do
While downloading the file, the dialog prompts to save file with myservlet.do which is really odd & when ur downloading a zip file the name says "save file myservlet.do"
If you dont understand any (:-) thing above see the below code.
response.setHeader("Content-Disposition", "attachment; filename="+ filename);
URL url = new URL("https://fyi/downloadfile/filename.zip");
conn = (HttpsURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream in = conn.getInputStream();
response.setContentType(conn.getContentType());
response.setContentLength(conn.getContentLength());
response.setHeader("Content-Disposition", "attachment; filename="
+ filename);
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int size = 0;
while ((size = in.read(buf)) >= 0) {
out.write(buf, 0, size);
}
in.close();
out.close();
}
try urself.
to know more about content-disp..
Subscribe to:
Comments (Atom)