Jayesh Pokar

Greenhorn
+ Follow
since Apr 26, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jayesh Pokar

Hi,

I am new to Spring framework......

I want to know by default which auto-wiring way will be used to inject properties value to the class.

As I read I came to know that there is no default autowiring available, so how it is getting autowired in the below case where I didn't mention anything for autowiring.

beans.xml file

<bean id="javaLanguage" class="LanguageBean">
<property name="languageName" value="Java"/>
</bean>

LanguageBean.java

public class LanguageBean implements BeanNameAware
{
private String languageName;
private String beanName;

setter & getter are there.

}

When I run the Program i got the value for property name languageName, So by which mechanism it get injected the value, how it came to know to use setter injection and not constructor injection?
Also is Dependency Injection same as Autowiring?
Please help me.

Thanks.
13 years ago
Here I am writing my attachment code.....

private int attachFile(File file){
try {

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message

messageBodyPart.setText(email.getEmailBody());

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);

// Part two is attachment
messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("greetings");
multipart.addBodyPart(messageBodyPart);

// Put parts in message
emailMessage.setContent(multipart);

} catch (MessagingException e) {

}
return 1;
}
13 years ago
H, I am sending mail with attachment but the problem i am facing is.....I want to show user that "Now it is attaching"....."Now it is sending mail"...such notification.
I am using Transport .send(msg), what it does is it attach the attachment first and then send mail, So I cant able to distinguish what is going on in background.

I use session.debug(true) , it notifies all things to me in console but what i want is some trigger or callback which says now attaching, now sending like that....

Here is my code..

public void send1() {

Properties props = new Properties();
props.put("mail.smtp.host", email.getSmtpServer());
props.put("mail.smtp.port", email.getSmtpPort());
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

try {
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(true);
emailMessage = new MimeMessage(session);
emailMessage.setSubject(email.getEmailSubject());



if(email.getAttachedFile().toString().trim().equals("")){
emailMessage.setText(email.getEmailBody());
}else{
attachFile(email.getAttachedFile());
}

emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getEmailTo(),"XYZ"));

Transport transport=session.getTransport("smtp");

transport.addConnectionListener(new EmailTransportListener(callBackObject));
transport.addTransportListener(new EmailTransportListener(callBackObject));

transport.connect();

InternetAddress[] a=new InternetAddress[1];
a[0]=new InternetAddress("[email protected]");
transport.sendMessage(emailMessage,a);

} catch (Exception mex) {
mex.printStackTrace();
}
}

Thanks.
13 years ago
thanks Nishan for reply.....

I tried with /filename and it works fine.

By specifying path in this way is what we are telling start looking for file from root, am i right?

So it will first look into src folder and then to res folder and so on, wherever it finds the file it take that file.

I want to specify look only into res folder, and I am not able to do that.

I tried with...
res/filename
/res/filename
./res/filename

where I am wrong?

13 years ago
Hi,
I am beginner in j2me and I am trying to access one text file but was unable to do it.

I am trying to access in this way

InputStream is=this.getClass().getResourceAsStream("res/test.txt");

Eclipse Project Structure
MyApp
- src
- res
-test.txt

I saw build path and res folder is included.

Please tell me the solution......Thanks...
13 years ago
Thanks for explanation...

My Question is..
1. So it means executing line s1=s+"e"; puts the value "abcde" into s1 and that s1 value will not go in String pool?
2. How much String object is made after executing above line?
3. As per said, that s is not compile time constant, that is fine but value abcde hold by s1 after execution of the above line, that should go in String pool because if now value of s will change so what does it matters?

Thanks....



13 years ago
Vishwanath,

As per you

String s="abcd";
String s1="abcd";

System.out.println(s==s1);

This should also give me false right and only s.equals(s1) should give true?

I want to know both s1 and s2 in previously mentioned program contain same string then why two different references, both should refer to same reference and s1==s2 should give me true...
Please correct me....where I am going wrong...

Thanks
13 years ago
When I run these program, I was expecting answer as true but it gave false?



String s1 and s2 both should refer to same address in pool having String as "abcde" right?
Can some please explain me the correct way of how it works?

Thanks in advance.
13 years ago
Sorry I forgot to mention.....If it is using URL rewriting internally then that Session Id should be displayed on address bar of browser that too is not happening.....

Please Help...Thanks
14 years ago
As far as i know HttpSession internally uses Cookies and if it is disabled then uses URL rewriting.....

i tried with small piece of code creating HttpSession and setting one attribute to it
I disabled my browser cookies......
Now when i run the program with cookies disabled n no url rewriting i did......still im able to get the attribute which i set on session....how come that is possible.....
Please guide me how it is working.....

Here is my code which i tried....

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.sas.zip1.ServletClass</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>MyServlet1</servlet-name>
<servlet-class>com.sas.zip1.ServletClass1</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyServlet1</servlet-name>
<url-pattern>/session2.spring</url-pattern>
</servlet-mapping>

</web-app>


ServletClass


public class ServletClass extends HttpServlet{

public void doGet ( HttpServletRequest request,
HttpServletResponse response )throws ServletException, IOException {
PrintWriter out;

HttpSession sson=request.getSession();
sson.setAttribute("nammee", "jisnussstttttt");


response.setContentType("text/html");
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(" Use of cookie in servlet");
out.println("</TITLE></HEAD><BODY><form method=get action=session2.spring>");
out.println(" <input type=submit><b>This is a Cookie example</b>");
out.println("</form></BODY></HTML>");
out.close();
}
}





ServletClass1

public class ServletClass1 extends HttpServlet{

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse resp)throws ServletException, IOException {
System.out.println("INSIDE NEW ServletClass1");

HttpSession session=request.getSession(false);
System.out.println("ID IS :"+session.getId()+ "VALUE IS : "+session.getAttribute("nammee"));
}
}


Please Help me out......Thanks
14 years ago