wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes Hi, trying to get spring-struts example to work... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Hi, trying to get spring-struts example to work..." Watch "Hi, trying to get spring-struts example to work..." New topic

Hi, trying to get spring-struts example to work...

carol otisman

Joined: May 07, 2007
Posts: 3
Hi, I'm learning struts-spring from example from http://www.roseindia.net/struts/hibernate-spring/integrate.shtml (I downloaded project.zip from the page), I have 2 issues with this example:

1. During runtime, I get error: "Resultset is closed". But, if I delete all "rs.close()" lines, it now works fine. This is in SpringHibernateDAOImpl.java. The only thing different is that I'm using sql 2000, and I changed was in applicationContext-hibernate.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>sun.jdbc.odbc.JdbcOdbcDriver</value></property>
<property name="url"><value>jdbc dbc:LocalServer2</value></property>
<property name="username"><value>deepak</value></property>
<property name="password"><value>deepak</value></property>

2. In the "Forgot Password" Page, for sending email: I get error: javax.mail.MessagingException: Could not connect to SMTP host:, port: 25; nested exception is: java.net.SocketException: Network is unreachable: no further information. I have no idea what this is and how to configure 'smtp'

Basically, I just got my new personal computer and downloaded this project to it, it'd be great if you can download the example straight from http://www.roseindia.net/struts/hibernate-spring/project.zip so that you can see the actual code I'm talking about, that'd be great !

Thanks again,
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
But here's what I think about your errors:

1. This is because your jdbc driver that connects to your database is probably closing the result set when you close your statement. This impl class is not done correctly there should be try/catch around each one and on an exception setting the object to null. If it were written like that you wouldn't have seen that error.

2. To send out emails you need to connect to a SMTP (Simple Mail Transfer Protocol) server ( a server that sends out emails). This configuration is in the applicationContext-hibernate.xml file at the very bottom. You have to have an email server running or have access to an email server for this to work properly. If you don't have access to a smtp server, there is a java one that Apache has for free download (I use this a lot for testing) http://james.apache.org/server/index.html. An example of SMTP is if you have a gmail account and you setup your gmail in your Outlook or Thunderbird application to send mail from those applications you have to connect to gmail's smtp server (smtp.gmail.com). Once you connect you give it your username/password to authenticate so it knows who is trying to send the emails, once you authenticate to the smtp server you can send out mail via your acount (youruser@gmail.com). This code is doing the same thing, it's trying to connecto to an smtp server and send out emails.

On a side note just looking through the SpringHibernateDaoImpl doesn't really use the power of spring/hibernate. There is a lot of code that could be simplified by using hibernate and spring together. But it's still using a lot of JDBC: For example, in the public Collection getUsersList() method you can just do List allLogins = getHibernateTemplate().loadAll(Login.class);

Hope this helps out a little, and good luck with spring and hibernate. But I'll tell you, once you go through it understand it, it can become very powerful tool, and reduce code dramatically.
carol otisman

Joined: May 07, 2007
Posts: 3
Hi Nick !, thank you so much for your detailed reply, I have 2 questions I hope you can answer:

1. Thanks for telling me this, I was wondering if you know any spring-struts-hiberate sites or tutorials that have sample project that I can learn from, any recommendations ?

2. That was a great and detailed explaination of smtp. Am I correct when I say: In my app, I connect to smtp server(has to be connected to internet), and the smtp server will send out the email ? To connect to gmail's smtp server, I need to first go through Outlook, and then connect to gmail's smtp server. If I'm connected to internet, is it possible for me to go directly from my app to connect to gmail's smtp server, just like I would with the Apache smtp?

I'm a new to all this, and I really appreciate all the help and comments you have given me.

Thanks so much,
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
no problem...

1. I don't know any good sites that pull those frameworks together into one application. I think Spring may have some example wars in their distribution. If you download spring there is a samples directory that they have war files/source code. I'm pretty sure they have a spring/hibernate example and a spring mvc vs. struts example. so you can see the diffs between spring mvc and struts. Other than that, I have been thinking about putting together a sample application that would just be downloaded and ready to run. Using Derby for a database, apache James for smtp server (only to send emails) and struts/spring/hibernate or spring/hibernate (using spring mvc). But I haven't had much time to get this done.
To learn these frameworks it's just taken time and a lot of examples and trial and error with me. I like to learn the basics of them first and then build off of them, but learning new frameworks takes time.

2. You are correct, an smtp server is just an email server that sends and receives emails. So if you want anything to get past your computer you will have to be connected to the internet (for example you have to connect to gmail's smtp server at smtp.gmail.com, if you ping smtp.gmail.com you'll see it's ip address on the internet). You can test locally, for example I use JAMES to send email to an email account on localhost (my local computer) from localhost. So I have my JAMES email server sending and receiving emails from itself.

On a side note, it's funny you mention gmail I was just writing code to use gmails smtp server last night using spring, currently I use godaddy's with my account there. I started wanting to use gmail because I signed up for google apps, which is really nice.

It is possible but I ran into a few issues because gmail uses ssl. I looked all over the internet and the only solution I found was people rewriting spring's javamailsenderimpl class. but I actually found a way to do it.
take a look at the api. I use this class to send emails.
here's my settings, and it worked for a while until I changed the from address from my account to a no-reply@gmail.com then all the emails like hotmail and gmail blocked the reception of the email.

host = smtp.gmail.com
username = yourgmailemail@gmail.com
password = yourGmailPassword
port = 465 // or you can use port 587
protocol = smtps

//the setJavaMailProperties I use
// i can't remember if I used that or below:

took this from the following link:

I don't do it the way above, I actually use spring to configure my mail sender and inject the sender into my services. but it'll do the same thing. I can't totally remember the code I wrote but if something's different I'll post it later.
carol otisman

Joined: May 07, 2007
Posts: 3
Hi Nick, thanks so much for your reply and information on smtp, I will study this !

Thanks so much,
viral viral

Joined: Dec 16, 2008
Posts: 1
Try this tutorial on Struts Spring Application using Eclipse IDE
Consider Paul's rocket mass heater.
subject: Hi, trying to get spring-struts example to work...
Similar Threads
HTTP Status 404 - Servlet action is not available
Sample Struts Project for Download
Struggling with Acegi authentication....
Hibernate with Spring
Which is Model and Controller in this example?