Gwt and jsp in same project - java

i was looking for similar title here but i didn't find much info, so if anyone can provide some example or url or any approach how to do it.
For example: is it possible to call a jsp from a gwt widget?
or communication (server - jsp) in gwt project and so on..
Is there any limitation is using jsp in gwt project?
Thanks :-)

GWT compiles down to html+javascript (static files), while JSPs are internally compiled and behave like servlets. You can configure URLs to point to both (via your server config and/or web.xml).
Both GWT and JSP allow you to go to a new URL. In GWT you can use Window.Location.assign(url) (this will load new URL and close current GWT app).
Additionally GWT allows you to load data by making XHR calls to URLs: http://code.google.com/webtoolkit/doc/latest/tutorial/JSON.html
So:
Yes you can goto JSP pages from GWT app.
Yes you can load data provided by JSPs into your GWT app.

In any jsp applications actions lead to URLs. The URL can point to a GWT module.
You will find applications which offer a back-end for the administrator in GWT, while the front-end runs in Struts2. Konakart e-shop is such an example.
My impression is that GWT will replace the other frameworks on the long run. Everybody will want Rich Internet Applications very soon.
On the other hand in the early 80's i was thinking that in very few years everybody would be using Unix, which never happened, but Unix did quite well after all...

Related

How to create java web form with spring, bootsrap, javascript that calls java method?

this is my first question on stackoverflow and I'm really confused..
I'm new with java and very confused at this moment. I'm planning to create a java web service with spring that handles a webform and a portable scanner device. I get this project for my first in new workplace but I can't move on. I don't know what are the neccesery steps to succeed.
What I want from the Application running step-by-step:
Open in an executable file that
Open a new browser window on localhost and shows a form
Filling out form with input fields, checkbox items, dropdown list,
commentbox,
AND Option for file upload from local and/or call startScan() java method.
startScan() = take photo from device and saves it to project's root folder and rename it as formatted date: "yymmdd_hhmmss"
submitButton()
onSubmitButton() the form data should be saved in database that
later i can download as xml
I have read lot of blogs and watch tutorials but that causes me confused. JPA? Hibernate? REST? REACT? I would like to create a very simple app that can display the form on window browser that is easy to access with bootsrap.
What is the neccesery toolset for doing this as simple as possible?
mysql? postgresql? which of these I can implement, what should i install locally?
If I could came out from back end to front that would be awesome..
Goal: Create a localhost database system that handles the form and scanner device method in a fancy css view.
Now, I'm using eclipse with spring. What are the neccesery dependencies? what are the local requirements for this kind of project? Please, help me with any advices..
I am very grateful for everything
Thank you in advance
I designed something similar, a simple two-page web application with login functionality and application main page that supports database operations and scanning functionality.
I would recommend you to go step-by-step since documentation is also as important, to be able to clearly visualize the project objectives, to know the constraints before-hand, make modifications on-the-fly and as a reference for your peers.
As a newbie with Java development, these are some basic steps and links which I feel would be helpful:
Project Scope Document (Web based tool: Draw.io)
Project Plan Document
Site Map (Web based tool: Draw.io)
Front-end Wireframing (Web-based tool: Balsamiq)
Back-end Wireframing (Microsoft Excel)
Back-end Flow chart (Web-based tool: Draw.io)
Front-end development (Technologies: HTML5, CSS3, Bootstrap 3, JavaScript; Tool: Brackets)
Back-end development (Technologies: PL/SQL or MySQL, Java, JDBC, Servlet, JSP, JSTL; Tools: SQL Developer, JBoss Studio)
Integrating Scanner (Third-party Java APIs)
Technology Stack: This is a simple and very generalized stack preference. You could customize it according to your needs.
Helpful Links on getting started: Java Web Terminology, JBoss Hello-world tutorial, Simple Java web application
Tools: Draw.io and Balsamiq are easy to use web based tools. You could use Bootstrap to make a quick fancy front-end. Brackets is a nice front-end code-editor supporting live-previews. SQL Developer is a wonderful tool if you're using Oracle SQL. JBoss Eclipse IDE has in-built application server which you can use for testing on localhost.
Note: All tools and technologies listed here are either free or include a trial version.
Hope that helps!

Protect Java EE webpage

How can I go to the source folder of a project by the browser URL in Java web. I want to ask that my project (consists of JSP and Servlets) is running at http://localhost:8080/myproject/index.jsp in Tomcat. If I want to go to the source folder that is myproject through browser's URL then how can I go? Simply you can tell that I want to hack this project, by knowing this I can prevent this access and can protect my website.
Not sure if this helps you, but if you're using some kind of Controller pattern (e.g. using Struts or a custom servlet that forwards to a JSP), the recommended way to prevent direct access to your JSP pages is to place them in the WEB-INF directory and then forward to these pages from your controller. See here for more details: How to properly put JSPs in the WEB-INF folder?
The Servlet 2.3 standard also defines how to prevent direct access in a similar manner (without putting them under WEB-INF), which then also requires to forward the request to these pages. For details, see here: http://www.jguru.com/faq/view.jsp?EID=471953

How to make a nice jsp GUI without using HTML tags?

I'm new to servlets and JSP and I'm trying to discover forms, and how to make my own web form. I know HTML but and I see examples for using HTML tags in the servlets, but isn't there a more higher level way to just say "Make a form here, make a table there" without getting my hands dirty with HTML tags?
I want to build a war file and drop it on my jboss/tomcat server for testing. Then when its ready to go, I want to be able to distribute that war file and for it to be plug and play.
The end goal is to have a web site with some interaction (dropdowns, text fields) and some graphs that are drawn based on the user inputs.
Sorry so vague, I need some direction in the Java GUI department.
Check out Java Server Faces. (http://java.sun.com/javaee/javaserverfaces/)
ps, I just noticed Wikipedia has a nice list of web-application frameworks for the various languages/environments.
One of the most difficult things to do absolutely right in a browser, is form submittal. That is, form submittal with error recovery.
Hence, it is a natural sweet spot for a helping library and many exist. I would suggest you look into JavaServer Faces where 2.0 with facelets is very powerful and default in Java EE6, but right now only ships with Glassfish 3.
If this is for learning, I would suggest using Glassfish instead of Tomcat, so you get a prepackaged learning environment.
You may be interested in the echo framework.
Try Google Web Toolkit
code.google.com/webtoolkit/

Using Java code on embedded HTML instead of JavaScript?

I am working on a project which is basically a Java application with an embedded IE browser (using JDIC 0.9.5) to display custom HTML files (stored locally that I created). I have a test HTML file with a JavaScript function that checks a simple form with checkboxes and alerts the user with a dialog stating which checkboxes are checked.
My question is, is there a way for my Java application to do the same procedure on the embedded HTML form instead of using JavaScript. I want to keep my application and HTML files simple without the clutter of JavaScript in my HTMLs or a pile of .js files.
Thanks for any help and guidance!
You have two options. Either shift the project to run the Java on the server side using JSP technology inside a web container like Apache Tomcat or Jetty, or write you web page to open up a Java applet.
The applet route allows you to run the code on someone else's machine, and as a trade off you will have to run the application in a strongly security constrained environment. After all, if someone were to run code on your machine, you wouldn't want it able to access your disk, etc.
The JSP solution will have you running the code on the same machine as your web server, since you (probably) control your own web server, the code will not be ran with as many security constraints enabled. This means the code can make requests to other machines, write and read files, etc.
You could replace your model with a client-server model using Java Server Pages (JSP).
If you are displaying the page through an embedded browser it is very unlikely that you will be able to get access to the DOM via Java.
One option is to use GWT javascript compiler to code in java and then convert to javascript. If it will only use IE, then you will only need to keep one of the generated .js files, so the clutter will be low.
Since you're embedding your HTML files in your own Java program, I would recommend you to use one of these 2 approaches:
1.- Use Javascript and structure the files cleanly, is not that complex.
2.- When you do the POST check the values in your Java code and return a new dynamically generated HTML file with needed info
I sincerely recommend you to follow the first option. Other options to work with Java in HTML would be JSP or GWT, but both will require a proper J2EE server, which would be overkill in your application

Java to JSP. How to?

i have written a java program which currently runs as a desktop app,
it is returning all results accurately as required in the console. I am now faced by a challenge to convert this application to a web application (JSP).
Currently, the code for my projects is in user/workspace (as i am using eclipse)
and my tomcat has been installed at c:/server/tomcat..
I am basically a .net developer and know peanuts about java web development. Can someone please guide me as to how i can convert my current project into a web application?
how do i include the project in user/workspace in the jsp file? havent done it before so its as confusing as hell.
it will be most helpful if you can point me in the right directon, or even provide some links so that I can use thm as a pointer
Many Thanks in Advance.
I suggest not to use the JSP technology anymore unless you have to (-> customer demands it).
Instead, get GWT or Grails. Both come with tools to setup a project in Eclipse from scratch that compiles and can be run with the press of a button. Also, both technologies are much more advanced than JSP and you'll find them much more simple to understand as a .Net developer.
If all you want do do is to display the output in a html page, the simplest ways is still to use jsp.
You can do as mentioned in kgiannakakis answer
If your class already returns a string with a nice output, everything you need do this.
<%
MyClass = new MyClass();
%>
<pre> <%-- pure html, preformatted --%>
<%= myClass.formattedStuff(); %>
</pre>
No fancy html formatting, though. Just a text dump.
You can use for-loops and if-clauses and what not, as everything between <% %> is normal java.
If you need more functionality, You should probably not bother with jsp at all. (And absolutely not at all with JSTL, which would be a total waste of time if you are not intending to start a career writing web apps for big enterprises.
Perhaps GWT :-) Its almost java.
I recommend reading a JSP tutorial. It isn't that hard. To get you started quickly, these are the required steps:
Create a web application. It is better to use a IDE like Eclipse or Netbeans to do so. A quick and dirty solution is to create the jsp under webapps/ROOT in Tomcat
The jsp is like an html file with some special tags that allow it to run java code.
This is how you include classes or packages:
<%# page language="java" import="mypackage.MyClass" %>
You put your Java code inside a <% %>. You can practically put all your java code there.
Replace System.out.println in your console app with the following tag:
The mymessage will be directly printed in the html source.
Finally start Tomcat and point to your jsp file.
For a beginner, I would recommend to start from a tutorial for Eclipse or Netbeans.
The technical part of converting your project into a web project is fairly easy. You can simply create a new static or dynamic web project using eclipse and copy your code into the source directory of that project. Google it and you're there.
The next step would probably be to understand how your application is deployed, and how do you configure it.
Keep in mind that you switch architecture here. A web application is a client server application that executes in a servlet container which comes with some rules unless all you need to do is print some text into a browser.
I suggest that you start reading here:
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html#99975
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html
The first link refers to Servlets, the reason I point you to Servlets first is that JSPs are actually servlets, and servlets are easier to begin with.
Hope this helps.
Try this, http://simple.souther.us it has all to get you started.

Categories