Question is pretty lame I know. And the answer is pretty simple - AJAX (I think, I'm not sure).
But before proceeding further, I would like to know if there's a better way.
My problem:
I have a web application, that takes in one statement from the user, and then in response to it,sends back another statement. The whole process goes on like this.
So how can I give a dynamic nature to my JSP then? If I keep reloading the JSP, my old responses will get deleted. So, that's not how it works.
I could use RequestDispatcher 's include() method. I find that as one solution. So, I can keep including the new pages onto my old JSPs. But again, I think this will have a limitation. Haven't tested it yet though.
Is there a better way around?
Thanks for your help. :-)
I'm in love with AJAX consuming Restful Webservices so that is what I would suggest. In addition, if I understand you correctly, I don't think include() will help you in this scenario unless you manage to keep streamming your responses in 1 open connection which isn't really ideal in most Web page scenarios.
Related
I'm interested in the front controller servlet:
https://martinfowler.com/eaaCatalog/frontController.html
I'd like to stick to servlet as much as possible, but am not terribly keen on using a multitude of system.out commands to print html.
How would I use "fragments" of html, stored literally as foo.html and bar.html, for different servlets to mix-and-match.
Yes, this a poorly researched question as it stands. I'll add research too it, only looking for general information please.
I'm new to JSF.
I have two use cases.
1: URL: https://site.com/context/part/{partId}
2: URL: https://site.com/context/register-token?tokenType=xxxxxx&token=xxxxx
in each of these cases i'd like to extract the variable information, execute code in a java class (scoped bean/#PostConstruct, i presume) then display appropriate content based on the values.
I'm sure this is pretty straight forward in JSF and I have seen quite a few nice suggestions on how to do pieces of these, but they seem to not be without controversy, so I can't say they're the correct way due to my ignorance. Additionally there seems to be significant enough changes in 2.2 the older posts could be out of date as far as "correctness" goes. Lastly there doesn't seem to be a guide (that I can find) that specifically talks to these workflows specifically in 2.2.
Can anyone provide me a semi comprehensive "correct" way to do these things in JEE7/JSF2.2?
Correct can be subjective I know, but my thinking though this seems rudimentary enough that in this case a vanilla happy path suggestion would be enough.
Much appreciated, thanks.
Finishing comment from above as the last issue has been resolved...
For workflow 1: i found this and it worked: http://www.oracle.com/technetwork/articles/java/jsf22-1377252.html
But it seemed limited to query params.
For workflow 2: I'm using prettyfaces and i was able to get it to work ~sort-of~ by using this (Section 3.6): http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.actions
My web assets not resolving issue was resolved, by using this tip given by #chkal: PrettyFaces using mapped urls and actions, i lose all my stylings.
This suggestion pushed me over the edge to abandon a pure JSF solution and use pretty faces especially since im going to lean towards workflow 2 more often than not: Should I use f:event or action element in PrettyFaces?
I have a problem. I need execute js webscript from Java webscript. I know, how do it:
req.getRuntime().getContainer().getRegistry().getWebScript("com/home/testJs/testJs.get").execute(req, res)
, but how to construct the new WebScriptRequest object? I need do it for rewrite request path. It's a really problem for me.
Thank you.
In general, you should use WebScriptRequestURLImpl. Without any other detail, it's hard go any deeper.
That said, it's in general a bad idea to go through yet another HTTP call to yourself to fix your problem, it's basically an indication of poor modularization or lack of code reuse.
I'd rather move the piece of code that's common in both the JS and Java web scripts flows to be an Action, which you could invoke from both places without having to repackage the input parameters, or worse send them via HTTP.
Of course skuro is correct saying it is a bad idea going through the HTTP layer twice.
But in fact, executing both, a script controller and a java method is supported by Alfresco right out of the box - without ugly hacks, and without passing the entire HTTP layer twice.
You may do this:
Put your script code in the corresponding .js file.
Make sure your Java class is a subclass of DeclarativeWebScript, override executeImpl and put your custom logic there.
Sure, you can still argue that having two controllers is bad style. :)
I have a Spring-MVC based webapp with a JSP front end. It is your basic CRUD app with various other management and reporting screens thrown in.
We are currently using JSP with JSTL for our view, but our designer doesn't know JSP so it's been a real pain to merge his design changes into the source. Due to that, my recent thought has been that if we could just hand the entire UI over to him and let him implement it entirely in HTML/Javascript, making ajax requests for JSON data for the dynamic portions, we would be able to remove that entire merge process and just host his static HTML files. Development for him would be simple as he would be able to hit our REST webapp on our test server for sample JSON data using jsonp.
If the designer is proficient with javascript, what would we lose by changing our spring-mvc webapp to only return JSON views and use jQote or jquery-tmpl to do all dynamic bits in the HTML?
Are there any deal breakers in going this route?
You'd just lose the ability to take advantage of JSP-based frameworks and templates. If:
your developer is proficient in Javascript,
you expect future developers in his place to be proficient as well, and
you are okay with making javascript a requirement for your site
then this can be a good strategy. The JSON will probably make your AJAX calls a lot faster than returning actual content would do. You'll probably be able to make the site a lot more responsive to user interaction.
The problem with injecting content via JavaScript is that search engines cannot see it. They get the page source as it is a load time. If this is an internal application that may not matter, but if it's a public-facing site it could mean very bad things.
You can build entire interfaces from JSON data and a bit of JavaScript on the client. As a technique it works quite well and is fast, but beware of the SEO implications.
One more point to add:
Say you are loading 300 rows of data to show, then you will have to load 100 row using JS and then show it to user.
It will mimic the streaming features. Content will be shown after request is populated.
I'm thinking about making a simple web application to practice custom tags, EL, ...
Now I'm thinking about how to make a simple front page.
I want to have a front page where I'll show a short description of a post and then the user can click it to see the full article.
Further down the line I'd like to attach a poster to it, and even further down the line I'd like to allow people to leave a comment.
Now I see two ways to do this:
a) put it all into a database
b) put the short description and the article into a .tag file and put the comments and users into the database.
Now I'm wondering which way would you go, or would you go for something entirely else?
The first way is probably the easiest but it does require access to the database "often".
The second way is a bit more "sloppy", especially depending on my implementation but it does have the advantage of accessing the database less often.
And any recommendations on keeping the data actual?
I could either load everything each time somebody accesses the news page, or I could put it in the application scope and put the articles into a bean and use a listener.
And do you use hibernate/jdbc/... for a database connection?
I'm getting the feeling that the actual programming will be the easiest part.
Any directions (or book recommendations for that matter) are welcome.
I've read head first servlets & jsp, and while it does a wonderful job of explaining how to develop the application I find it a bit lacking in the when/how to connect with the database and how to optimize it.
Sorry for the long post that possibly doesn't really fall under the scope of this site.
As far as I can see, you are thinking too much about performance. You should not. It is of a little concern in the start. Go what feels right. Tackle performance when its actually lacking.
I would suggest you
You should use some pooling mechanism for database connection. Its very important and make the process very efficient. Take a look at DBCP or C3P0 or something.
to go store your data into the database, even the short description, in some appropriate table.
Moreover, don't load everything when somebody accesses the page, it might go futile and it will take a lot more time and the user gets frustrated.
you can cache data later when you feel its a good idea. Hibernate provide caching real easy, you might try to incorporate Hibernate, as you mentioned it yourself.
you can use AJAX calls wherever appropriate to get rapid request/response.
These are few things I like to mention.