I have nearly 20+ pages from different Web application that a user can access once he login. I have this 'Recent Activity' section on my Home page where I have to show the last 10 visited pages by the user ( if possible along with date and time of visiting). The pages are jsp pages. I dont know how I can acheive this basically I am more a frontend developer so can I do this with jquery, jsp, js etc.. or anyother technoloiges. We use Java technology also. Please let me know any sample code or way of approach to do it.
Thanks
I am a php developer, not too familiar with jsp, but i am sure it would be the same logic.
You have 2 option here:
Option 1:
Create a database table and record all the user flow whenever the user access an application.
Option 2:
Save all the flow in a cookie variable so whenever the user logs in you can pull out all his info from the cookie variable.
Personally i rather use the option 1, because if the use clears out the cookie/session variable you will lose lo all the information.
Since i am not a jsp i can't providew with a sample code. Hope this get your started at least.
This information may be stored on Cookies or User Session.
If it's available on cookies, you can access and manipulate it using JavaScript or any other server-side languages.
Do you want some example on how to use it using JSP&Servlets?
There's pros and cons for each approach.
Cookies: User can cleanup private browser data, and cookies go away with it.
Sessions: You can store it in some database or log file, for future load or/and analysis.
Cons is the management of this data in any layer. But it's not a big problem.
Related
As an application to get a job I need to make a web app. I'm only familiar with Java SE so here comes my concerns. I need to make web service where at the beginning there will be authentication window, then I need to show the JSON data (probably parse it and show) as table or as list with button near to choose one of the row from the table to get to the next page where there user can choose a materials and so on.
I have data in JSON on server I need to pull it from there, then I need to show data which looks like this /materialDetails?ID=x where x is ID (it's probably HTTP or URI). Should I use Java REST? If yes I need to create a site in XML and then put java data inside? There're only a few tutorials on the internet and I can't find any good(sometimes the problem is in server, sometimes with dependencies). I was looking for information also on youtube but except https://www.youtube.com/watch?v=X36Dud8cS4Y I cant find anything useful? Could someone explain me this to make it at least a lil bit easier? Or just lead me to pick a specific framework. Thanks in advance
You could create a Dynamic Web Project with Tomcat and a MySQL Database for starters. You could use RESTEasy to create a WebService that gets data from your Database.
I don't know what exactly is expected from you, but this might be a good start. "Making a web app" is a bit like saying "I need to develop a java program", it is a bit vague !
I don't know REST but I think your application can be implemented with this technologies: HTML and Servlets/JSPs.
I would write an authentication page in HTML (one form element with 2 inputs and a button) which would pass credentials to a Java Server Page or a Servlet (they're equivalent). There I would build the table (another HTML element) thus producing a new HTML page.
P.S.: you're using JSON as a format so there's no need to learn XML.
I need to prevent duplicate form submissions for my customer's website.
we need some form data from user for order confirm page.
we use load balancing for web server.
Approach 1 : Post/Redirect/Get
(PRG pattern : http://en.wikipedia.org/wiki/Post/Redirect/Get)
I was trying to use PRG pattern at first.
in this case, I think I need to deal with session(or spring flashmap) across multiple web server.
Approach 2 : Disable refresh on client.
one of my colleague suggested this approach.
Approach 3 : Post/Post
another colleague suggested this approach.
I think approach 2, 3 is not a good choice.
but I do not know the specific cons or security risk about these approaches.
I tried to google, but I failed to find answer.
Thank you in advance.
[Edit]
I would like to update the pros and cons.
Approach 1 : Post/Redirect/Get
pros
Safe!
cons
if you need some form data from user to show it on confirm page, you need to use session ,database or something.
if you use session, and have more than one server, you have to do something to make session available across multiple servers.
Approach 2 : Disable refresh on client.
pros
cons
Users will get upset if you limit the browser standard features, like refresh.
need to consider F5, Ctrl+F5, ⌘ + F5 etc, various refresh icons.
In mobile, many web browser automatically refresh page when user reload browser.
Approach 3 : Post/Post
pros
You don't have to worry about session sharing issue across multiple servers.
cons
Second form submit can fail.
Approach 1 is a pretty straight forward method that solves some duplicate post issues. It won't cope with server lag and which is a reason for duplicate submission.
Approach 2 is nothing but wrong. Users will get upset if you limit the browser standard features, like refresh. That is, if you are even able to do so technically cross browser. You need to consider F5, Ctrl+F5, ⌘ + F5 etc, various refresh icons.
I must admit that I don't fully understand the intent of Approach 3, however, it feels a bit wrong to bounce the user to an empty page.
Another standard approach is to use a nounce with form posts. This will also help you avoid a security risk called Cross Site Request Forgery. It's pretty simple.
Generate a "unique" random string on the server, called nonce.
Insert the nonce into the database.
Attach the nonce to the form as a hidden field (or pass by URL or similar).
Make sure the nonce is sent along in the form post to server.
At server side, validate the nonce, remove nonce, "save form data".
Display confirmation page.
If you get another request with a non existing nonce, then you know it's either a duplicate post or some more evil CSRF attack.
You can probably find some support library that does this for you.
I am trying to scrape a website, using Web Client, i am able to get the data on the first page and parse it, but I do not know how to read the data on the second page, the website is calling a java script to navigate to the second page. Can anyone suggest me how do I get the data from the next pages?
Thanks in advance
The problem you're going to have is while you (a person) can read the JavaScript in the first page and see it is navigating to another page, having the computer do this is going to be hard.
If you could identify the block of code performing the navigation, you would then need to execute it in such a way that allowed your program to extract the URL. This again is going to be very specific to the structure of the JavaScript and would require a person to identify this.
In short, I think you're dead in the water with this one, though it serves as a good example of why the Unobtrusive JavaScript concept is so important.
This framework integrates HtmlUnit with its headless javascript enabled browser to fully support scriping multiple pages in the same WebClient session: https://github.com/subes/invesdwin-webproxy
what kind of tool or approach would you suggest for the following scenario:
JSP/Servlets web application
need to design forms and connect this forms to actual data from the db (for example select form fields from a specific list of fields) while the web app is running
save and use the above forms to store data to DB
any approach or tool indication is welcome
The basic idea would be:
h have the possibility to design a form from the application and then have user use it to store data, for example the administrator logs in, creates/designs a from with certain fields (connecting those fields to actual data from the db), stores that form, publishes it to be used by users. The user logs in, selects the just-published form, inputs data, saves to db
EDIT: i am receiving downvotes, while it is ok, as i am mainly looking for advice, please do state what makes this question so unbearably bad that you need to down-vote, without maybe giving a hint to what i should change. It seems to me that the question relates to a specific problem i am facing, while trying to build a solution.
EDIT 2: i need to design the form while the application is running, and use the form again from the app. It has nothing to do with coding forms in a JSP page or connection to databases or things like that.
I am looking to develop an app that will take login details from the user, go to a website, login, return values on the web page and then display them to the user on the phone.
Does java have this functionallity? Will I need to use javascript instead maybe? do these answers depend on the website that I am trying to access?
In my head I figure that I could just read in the paramaters as strings or chars, parse the webpage for the appropriate form and "paste" the appropriate value into the form "box". However, I have never attempted anything like this with coding so I am completely new to the idea and dont really know where to start. I tried googling around but any information that I found was either irrelevant or conflicting.
I'm not looking for the code to do it because I will not really learn anythig from that but a finger in the right direction would be great. I really do want to try get better at programming so that's why I've started to give myself these little side projects
Any help that can be offered would be great
Ian,
You can try using http-client (http://hc.apache.org/httpclient-3.x/) lib from apache. It lets to pro grammatically access a website (from a Java code). You will need to do the following things
Use the http-client lib to POST the data to the web site.
Receive the html response.
Use some html parser or xpath to retrieve the values from the response html.
You would need a script which accesses the webpage and enters the data, but in my opinion this is illegal. Because you are accessing a secured area and are able to look into sensitive data. Also accessing the page via a script is "botting" - most pages have safety precautions to prevent the execution of scripts, because most of them are harmful.
In my opinion there is no legal and easy solution to this.