I'm working with GAE (Java) in my GWT application.
When my users enter a certain URL I'd like to dynamically create an html page on the server side and serve it to the client.
How can I do this? Using HttpServlet?
I'm quite lost here, do I need to have an html template file on the server side that I dynamically complete and serve to the client?
You should start with the tutorial to learn the basics. You can generate the whole HTML dynamically, but that tends to get awkward. It's better to separate the HTML to a template and fill in the details with the logic implemented in the GAE application.
https://developers.google.com/appengine/docs/java/gettingstarted/
You can use a library like this one https://github.com/alexmuntean/java-url-rewrite . Read the readme to understand more.
You can just take the request and serve anything you want (jsp, jsf, html static). And you can also write gwt code to do actions(effects or ajax for more things. Etc) with the existing html (just add ids to elements) And write another entry point for that page and just include the generated js in your page
I am planning to do a tutorial and POC on how to make a gwt website indexable by google
Related
I've been playing around with some Spring Boot tutorials (most importantly Building A Restful Service). I am getting output as JSON in my browser.
I would like to know how I can read the JSON into HTML & CSS to make it look nice. My three java files are 'Application.java' 'Greeting.java' and 'GreetingController.java'.
I don't want to overload with my code, but basically I made it so that when I enter
localhost:8080/greetings/add?name=User ('User' can be whatever)
it adds the user to an Arraylist, and then at localhost:8080/greetings it prints out all the greetings, like this:
How do I get it to be read into HTML & CSS, so I could get something like this (different content of course, but just a table that takes in the JSON)?
Here's the github link if interested: https://github.com/josephmalisov/SpringBootGreetings
The Spring guide "Serving Web Content with Spring MVC" provides an answer. In your controller, add your object to your model and then return the name of a template page. e.g.
model.addAttribute("name",name);
Loops in Thymeleaf are an easy way to build your table. Include your github repo and I'll send you a pull request (maybe).
I would like to here few expert advise to make this decision.
We have web app angular as UI and spring boot as back end.
requirement is to generate PDF of dashboard which we are showing on UI contains few data table with client side pagenation and also need to add extra header footer in pdf which we are not showing currently on UI. font requirement is given by client and must follow.
Considering following two options--
1. Itext pdf generation in java where we will design pdf similar to UI dashboard.
2. use some js library like jspdf and write dashboard inner html to pdf.
Need to understand what is pros and cons of each approach,which is good out of both?
Since you have client and server side options I suggest it's worth prototyping a typical document in both approaches (if you can spare the time). The reason is that there are advantages to each and it depends really how specifically you want your PDF to be like your html.
Generally I prefer server-side generation because:
you have access to data possibly not on the client (eg what is going into your header and footer maybe)
you can store the document server side (if relevant) then deliver to the client
However you said "font requirement is given by client". If the client is subject to change and you need that reflected automatically in the paginated PDF, then Amedee's suggestion of html to pdf might be your best option.
I hope that helps.
Paul.
So if you want to take input from an html form and put that into a database, you can have the form's action direct to a php file like example.php. That php file can then manage database calls with like mysqli_connect() and whatnot.
My question is, what is the equivalent of this when you want to use a Java back end instead? Do I have the form's action direct to a .java file? I know how to use Hibernate for databases, but I don't know how to connect the input from the web form to my Java code.
I have no clue what terms to even google for. I tried "java back end tutorial" but that wasn't useful at all. I'd appreciate any simple explanations, or even the correct technologies to look up.
You can develop Web application and Web site with Java. Google it and you will see a lot of tutorials on how to do it.
The initial technology to develop Web apps with Java is Servlet or JSP as said above by user2963623.
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
I am helping someone out with a javascript-based web app (even though I know next to nothing about web development) and we are unsure about the best way to implement a feature we'd like to have.
Basically, the user will be using our tool to view all kinds of boring data in tables, columns, etc. via javascript. We want to implement a feature where the user can click a button or link that then allows the user to download the displayed data in a .doc file.
Our basic idea so far is something like:
call a Java function on the server with the desired data passed in as a String when the link is clicked
generate the .doc file on the server
automatically "open" a link to the file in the client's browser to initiate the download
Is this possible? If so, is it feasible? Or, can you recommend a better solution?
edit: the data does not reside on the server; rather, it is queried from a SQL database
Yep, its possible. Your saviour is the Apache POI library. Its HWPF library will help you generate Microsoft word files using java. The rest is just clever use of HTTP.
Your basic idea sounds a bit Rube-Goldbergesque.
Is the data you want in the document present on the server? If so, then all you need to do is display a plain HTML link with GET parameters that describes the data (i.e. data for customer X from date A to date B). The link will be handled on the server by a Servlet that gets the data and produces the .DOC file as its output to be downloaded by the browser - a very simple one-step process that doesn't even involve any JavaScript.
Passing large amount data as GET/POST around might not be the best idea. You could just pass in the same parameters you used to generate the HTML page earlier. You don't even need to use 3rd party library to generate DOC. You could just generate a plain old HTML file with DOC extension and Word will be happy to open it.
Sounds like Docmosis Java library could help - check out theonline demo since shows it something similar to what you're asking - generating a real doc file from a web site based on selections in the web page. Docmosis can query from databases and run pretty much anywhere.