I have to do a project where I need to make both desktop (Java) and web application (JSP) which do the same thing -- upload files on a web server where file,user,group informations are stored in a database (MySQL).
What I want to know is: can I first make a desktop app with Java that does uploading and database "fiddling" and THEN get to the web app programming? Do I need to use Servlets/JSP even though I make first a desktop application. So that's my question.
Basically, can one app be done without making part of another?
5 replies to this topic
#1
Posted 01 June 2011 - 09:58 AM
|
|
|
#2
Posted 01 June 2011 - 11:15 AM
If you make your desktop program somewhat decently, by which I mean you separate your GUI well from your "real" code. Then you can propably reuse the whole backend for your web app.
Say your Gui is like this:
If there is no code from Gui needed in the model, then you can use model and StoringObject in your servlets / jsp as well to do saveOrUpdate().
I'd say "yes"
Say your Gui is like this:
private class Gui{
private Model model;
//onlick from button:
public void actionPerformed(ActionEvent e){
StoringObject object = new StoringObject(getFile(), getUser(), getGroup(), getInformations());
model.saveOrUpdate(object);
}
}
If there is no code from Gui needed in the model, then you can use model and StoringObject in your servlets / jsp as well to do saveOrUpdate().
Quote
Basically, can one app be done without making part of another?
#3
Posted 01 June 2011 - 11:57 AM
Thank you, wim DC!
That sounds good to me. I understand editing database, but uploading file to a webserver from desktop app was a bit unfamiliar to me so I was worried that I'll have to work on JSP to make some kind of a "bridge" before working on Java part. But since Java can do this I can go Database -> Java -> Java Server Pages.
That sounds good to me. I understand editing database, but uploading file to a webserver from desktop app was a bit unfamiliar to me so I was worried that I'll have to work on JSP to make some kind of a "bridge" before working on Java part. But since Java can do this I can go Database -> Java -> Java Server Pages.
#4
Posted 01 June 2011 - 12:18 PM
I assume you run the database locally, and not on a "real" database server.
Both your desktop app and webapp will connect to it trough (Assuming it's mysql db here)
Applications are often build up like this:

And both the desktop part and the web app part are actually "just" the presentation layer. This type of programming design should have the effect that each layer is independent of another.
"Data source" on the image is the database,
Data Access Layer (very often just called 'DAL') are classes doing only stuff with the database, usually 1 class / table in the database.
If your database has a table 'User', you will propably also have a class User (in the business logic layer), and in the DAL you'll have a class "UserDAO" which has only methods like saveUser(User user); deleteUser(User user); updateUser(User user); findUserById(int id); findUserByUsername(String username); etc etc. Just that stuff -- communication with the database.
Business Logic Layer (BLL) usually contains "copies" of your database tables, like the User I mentioned.
These copies of the database classes are often only POJOs, plain old java classes. Meaning, almost no methods, just constructor, attributes getters and setters. They dont DO stuff. That's done by other "Service" classes in the BLL.
These service classes will call the DAO objects and they will be requested often by the presentation layer.
Basically the service classes are the bridge between presentation & DAL.
Gonna stop talking about the layers now, guess it's allready confusing enough. I don't know what level of Java knowledge you got to handle all this layers and stuff.
In this case you can as well merge the DAL and BLL, so you'll do stuff like:
Both your desktop app and webapp will connect to it trough (Assuming it's mysql db here)
DriverManager.getConnection(jdbc:mysql://localhost:3306/);You gonna have
FILE Desktop-App ----->-----> model ----->----->Database ^ Web-app----->------>-------+And the 'arrows' also go in the other direction off course.
Applications are often build up like this:

And both the desktop part and the web app part are actually "just" the presentation layer. This type of programming design should have the effect that each layer is independent of another.
"Data source" on the image is the database,
Data Access Layer (very often just called 'DAL') are classes doing only stuff with the database, usually 1 class / table in the database.
If your database has a table 'User', you will propably also have a class User (in the business logic layer), and in the DAL you'll have a class "UserDAO" which has only methods like saveUser(User user); deleteUser(User user); updateUser(User user); findUserById(int id); findUserByUsername(String username); etc etc. Just that stuff -- communication with the database.
Business Logic Layer (BLL) usually contains "copies" of your database tables, like the User I mentioned.
These copies of the database classes are often only POJOs, plain old java classes. Meaning, almost no methods, just constructor, attributes getters and setters. They dont DO stuff. That's done by other "Service" classes in the BLL.
These service classes will call the DAO objects and they will be requested often by the presentation layer.
Basically the service classes are the bridge between presentation & DAL.
Gonna stop talking about the layers now, guess it's allready confusing enough. I don't know what level of Java knowledge you got to handle all this layers and stuff.
In this case you can as well merge the DAL and BLL, so you'll do stuff like:
User user = new User("wim DC");
user.save();
And save contains the query to the Database, fills up the parameters, and sends it on.
#5
Posted 01 June 2011 - 03:15 PM
No, it's not confusing but interesting actually and as soon as you started talking about having DAL and BLL I too was thinking to merge those two. I guess more serious applications go with separating these two layers but for the project I'm doing I was looking to simplify it. But I understand that separating the layers is important in big projects for easy reusing/updating of code and handling by more than one programmer.
So I'll have:
Presentation Layer
Logic Layer
Data Source
Database I need only to build once, of course, and logic layer can be used in both Java and JSP(or is it Servlets?), if I understood you correctly.
The difference is the Presentation Layer where in Java I need to use Swing components to "build" the looks of my app and in JSP use HTML & CSS (in which I have a pretty solid knowledge).
So I'll have:
Presentation Layer
Logic Layer
Data Source
Database I need only to build once, of course, and logic layer can be used in both Java and JSP(or is it Servlets?), if I understood you correctly.
The difference is the Presentation Layer where in Java I need to use Swing components to "build" the looks of my app and in JSP use HTML & CSS (in which I have a pretty solid knowledge).
#6
Posted 02 June 2011 - 01:08 AM
Yes, you're correct.
About the choice between JSP or Servlet. Both ways will work.
In fact, a JSP will become a servlet because of the Java compiler.
It's just that in JSP it feels like you're working on a html page, so it's easier to do html stuff there.
As in a Servlet you just got a big String to print, won't get much help from an IDE there (except if it's a good IDE ^^).
Basically, if you're going to show a page to the user, create it with a JSP. It's gonna be easier, your IDE probably will have some kind of code completion to help you with that.
When can you use servlets then?
Well, I'm thinking of form actions. When you let the user fill in a form and it needs to be put into the database on submit, the servlet is a good way.
form.jsp:
If there is little html and much java code -> servlet.
If there is much html and little code -> jsp.
About the choice between JSP or Servlet. Both ways will work.
In fact, a JSP will become a servlet because of the Java compiler.
It's just that in JSP it feels like you're working on a html page, so it's easier to do html stuff there.
As in a Servlet you just got a big String to print, won't get much help from an IDE there (except if it's a good IDE ^^).
Basically, if you're going to show a page to the user, create it with a JSP. It's gonna be easier, your IDE probably will have some kind of code completion to help you with that.
When can you use servlets then?
Well, I'm thinking of form actions. When you let the user fill in a form and it needs to be put into the database on submit, the servlet is a good way.
form.jsp:
... <form action="saveServlet.servlet"> <label for="name">name: </label> <input type="text" id="name"/> <input type="submit" value="submit"/> </form> ...
If there is little html and much java code -> servlet.
If there is much html and little code -> jsp.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









