my main Problem I is that I'm new to this topic and don't know how to successfully google it.
I have a Java-program up and running which is just console-based (no GUI). I want to have a browser interface for it. I want to know how to:
Make a Link on a HTML-Page so that it calls a method in the java-program when clicked
print text from the java-program to the Html Page
enter Strings in a Input field and pass them to the java program
Simple exaample: A simple page with one input field, one "submit"-button and one text field. I enter a name, press submit, the java code gets the string, manipulates it, passes it back to the html page where it is displayed.
The question might seem simple but I need a place to start. Any tutorial link would be very welcomed.
Cheers
Google for Java Servlet programming for beginners
couple resources:
http://www.journaldev.com/1877/java-servlet-tutorial-with-examples-for-beginners
http://www.youtube.com/watch?v=tkFRGdUgCsE
I strongly recommend to study Java 2 Standard Edition before dealing with servlets.
You need to deeply understand how does the core java work, and only then approach to more complex technologies.
Good luck.
Related
I have worked with Java in the past but have never created a visual user interface, only programs that read from the command line. I would like to create an interface that displays a box with text stating the required input on the left and on the right a blank text field that can be read from by the program. This is for a web app I am working on at my internship, I have very little guidance and would really appreciate any help as I am completely lost at this point. The program currently only reads line by line which is obviously unacceptable for a web app.
Thank you so much for any assistance you can offer.
You can use the browser as your user interface. Create an HTML file to create your form for the user to enter data (which they view in a browser like Google Chrome) and submit back to your app. JSP files are the java equivalent of HTML files with optional java code inside. Download the Eclipse IDE and the Tomcat server and run one of the tutorials for creating a web app. Here's a link to start: https://eclipse.org/webtools/community/tutorials/BuildJ2EEWebApp/BuildJ2EEWebApp.html
I've created a website portfolio and I want to show some of the projects I've done. But so far the many of the projects I've done have been in java, or C/C++ and the interactive/fun programs take input from the console.
I was wondering if there was a way to simulate those program using JavaServer Faces and taking input from a textbox (possibly) to be used in the java program I've created and posted back to the website.
Just to give you an idea of the kinds of programs I'd like to show. They range from simple things like determining if the entered data from the user is a leap year to a text I/O credit card validation program I've made up.
If my question is clear enough, does anyone have any ideas about how I can show the programs I've created?
I thought of creating a java class that writes the output data from the java file in a String and then posts that to the webpage, but then the user would have to frequently refresh the page. So I thought if I could somehow simulate the console on the website that would take care of that problem.
Extra: Is there any easy way to display javafx programs on a website?
Thank you in advance!
I have an HTML form that I want a user to fill out, and then send by pressing a button. Is there a way to have that button run a java program with all the HTML input as parameters? I looked into this a bit, and most people recommended servlets. Is there a way to do this without a servlet?
Edit: I'm not trying to use a servlet because of restrictions.
If you have a restriction against running a servlet you're pretty much out of luck in terms of using java. You could use a JSP, but that's just a servlet at the end of the day. You could use javascript to pop-up a mail-to with the form parameters entered as the body of the email but that would assume the user has a mail program configured. You could use some service like http://www.emailmeform.com/ (I have no idea if this one is good, I just googled it...).
Check out Java Web Start, might be what you're looking for.
Are you running the java client-side or server-side? The two posted answers are client-side answers. As for server-side, the tutorial here might help, depending on your server.
Although I've been programming for a few years I've only really dabbled in the web side of things, it's been more application based for computers up until now. I was wondering, in java for example, what library defined function or self defined function I would use to have a program launch a web browser to a certain site? Also as an extension to this how could I have it find a certain field in the website like a search box for instance (if it wasnt the current target of the cursor) and then populate it with a string and submit it to the server? (maybe this is a kind of find by ID scenario?!)
Also, is there a way to control whethere this is visible or not to the user. What I mean is, if I want to do something as a background task whilst the user carries on using the program, I will want the program to be submitting data to a webpage without the whole visual side of things that would interrupt the user?
This may be basic but like I say, I've never tried my hand at it so perhaps if someone could just provide some rough code outlines I'd really appreciate it.
Many thanks
I think Selenium might be what you are looking for.
Selenium allows you to start a Web browser, launch it to a certain website and interact with it. Also, there is a Java API (and a lot of other languages, by the way) allowing you to control the launched browser from a Java application.
There are some tweaking to do, but you can also launch Selenium in background, using a headless Web browser.
as i understand it you want to submit data to a server via the excisting webinterface?
in that case you need to find out how the URL for the request is build and then make a http-call using the corresponding URL
i advice reading this if it involves a POST submit
I had to take a surveymonkey survey today, and the format was as follows: a question was asked, then after hitting the next button, the answer was displayed as "Answer: _" along with an explanation. For kicks, I'd like to make a program that could take this survey, answering any letter, then going to the next page and reading the answer, then going back and changing the answer to the correct one, then going 2 pages ahead and repeating.
I am familiar with Java and Python, but I'm not sure how to make them be able to "know" where the button is, and how to "read" text without unnecessary image recognition.
This is just a fun project, nothing serious, but I would appreciate any ideas to get me started.
Assuming that the text was just that (text rather than images), there are a few useful tools for you:
.Net WebControl - I've scripted this before from .Net. It has the advantage of making all of the JS on the page still work. I know this isn't Java, but it is surprisingly easy to work with for this kind of task.
Selenium - It is primarily a web testing framework, but it would be easy to script it from Java to auto-submit forms.
TagSoup for Java - If the pages do not have significant javascript code that needs to run, there are many HTML parsers for Java that could potentially be used to develop a scraper.
Would it be unrealistic to make it post to the survey monkey pages? You could then do some regex's to pull "answer:__" out and look for that pattern in the original page. It would definitely be easier than trying to click things in a browser, etc. Basically, write a java app or python for that matter that does http posts to the survey pages in order and uses regex's to find the next page, etc and then use a stack to keep track of the history.
Edit if this isn't clear, let me know, I'll clarify
Edit 2: I completely forgot about HTMLUnit, my bad. It is a testing framework like suggested by jsight but specifically for Java and functions very similarly to JUnit, however, because it is designed for testing web applications, it can be used to automate interactions with other sites
You can do it using a simple image search. First screenshot the a unique part of the button and save it. This will be used as the relative reference on where you click the mouse. Then during the actual running of the application, have a screenshot of the entire screen and find a part matching the previously saved image and then let the mouse click on the appropriate location based on the button image location.