• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Getting Errors When Trying to Compile

 
Ranch Hand
Posts: 2202
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting this message when trying to compile following code:

c:\AD_Test>javac HelloKDC.java
HelloKDC.java:1: error: class, interface, or enum expected
<!DOCTYPE HTML>
^
HelloKDC.java:153: error: class, interface, or enum expected
</BODY>
^
2 errors

 
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot compile HTML as if it were Java. And you cannot use Java as the body of an HTML page.

What on earth are you actually trying to do?      
 
Steve Dyke
Ranch Hand
Posts: 2202
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You cannot compile HTML as if it were Java. And you cannot use Java as the body of an HTML page.

What on earth are you actually trying to do?      



Just something I found on the net. Trying to test a connection to our KDC.

My overall goal is to be able to have a Single Sign On(Windows Log On) for my web apps and access the Active Directory for access control.  
 
Ranch Hand
Posts: 66
3
Netbeans IDE Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a little confused as to what you're actually trying to do here... Is this supposed to render a web page or execute a java program? Or is it supposed to do both? Also where did you get this code? It looks like you grabbed the java from sourceforge and wrote the html yourself? I'm looking at your post history and it looks like you have a lot of experience with Javascript, jQuery, and experience with Java too, but I'm really not sure what part you're hung up on, and the fact that you're trying to put HTML and java in the same file is scaring me, so I'm just going to go through everything. If this explains a lot of stuff you already know, sorry!

It looks like what  you're trying to do is make a program that displays an HTML page, then submits data to a java program when you click "submit." Java and HTML are two completely separate, different things. Getting them to talk to each other is hard. To do that, you're probably going to need to use some kind of framework designed specifically to help HTML-type pages talk to Java programs, like Spring or Struts, or you could use just plain servlets in a Java Web Application.

The basic structure you probably need looks like this:

You have a Java Web Application project. You also have a server, which is just a piece of software which you hand your project to, and once it has your project, it runs it for you and handles requests made to the pages you set up in your project.

Java Web Applications have a folder called "Web Pages" that contains HTML and JSP files. Your project will have a folder that contains java source code files, which includes servlets. The source code folder can be divided into "packages", which are just collections of java classes that you've decided to put in their own folder. Servlets are just java classes that accept data and do things with it. In order to use them though, they have to be paired up with a name so that your pages on the front end know where to send their data. That pairing is done in another file that all Java Web Applications have, it's called "web.xml", and a typical pairing of a servlet to a name will look like this:


Most of the time, the servlet-name will be something like "heightSubmit", the url-pattern will be something like "/heightSubmit", and the servlet-class would be something like "servlets.heightSubmit". What I'm getting at is they're usually all pretty much the same, but I made them different in this case to show how they relate to other things in the project. The "servlet-class" tells the project how to find your servlet by telling it exactly where to find the class file. The servlet-name is what ties the "servlet" to the "servlet-mapping", and the "url-pattern" is what you're going to use to reference the servlet when you actually have some data to send to it.

An HTML file is a document that tells a browser "Hey, this is what goes on this page." A JSP file does the same thing, but instead of just being a static document describing stuff, it's actually a java class file that prints stuff out directly. When you edit it, it looks like you're editing an HTML file, but it's actually different. JSP files are allowed to have what are called 'forms', and they look like this:



That basically says 'Hey, I'm going to put a box in this page, and when the user puts things in it, I want you to remember what's in it and make it so whatever servlet is located at "heightSubmit" can look at it too. When you submit this page, the server will say "Someone wants me to send this data to the servlet that's mapped to "/submitTheHeight"... I found a <servletMapping> that's mapped to "/submitTheHeight". The servlet-name is "heightSubmit", so I need to find the <servlet> that also has a servlet-name of "heightSubmit"... I have a <servlet> with a servlet-name of "heightSubmit", and for that <servlet>, the
servlet-class is "servlets.submitHeight", so I'll pack this data up in a special way that the user doesn't need to worry about understanding and send it over to the java class file located at "servlets.submitHeight".

Explaining the rest would require that you have some basic understanding of java, and I'm not actually sure what level you're at, so I'll throw the rest of it down here, but if this next part sounds like gibberish, do the tutorials down below and come back to this later:

Your servlet will receive the data in the form of an "HttpServletRequest" object, which I usually just call "request". You're also given an "HttpServletResponse" object, that I usually call "response", that you can use to send stuff back to the browser when you're done doing stuff with the request. You can call getParameter(String parameterName) on that request object to pull out the stuff that the user typed in on the page. Note though, that getParameter only ever pulls things out as Strings; if you want it as a number you'll have to convert it. So to get the data out that they put into the input box that had the name "height" and store it as a String object so you can do other stuff with it, you would do this:

String userHeightInches = request.getParameter("height");

Then at the end of the servlet you can use the response object to do some other things, like send the user to a new page by doing this: response.sendRedirect("theNameOfANewPageToGoTo");

So at a minimum you're going to need a Java Web Application project containing:
 - Some Java class files which can be used as servlets,
 - Some JSP pages
 - A web.xml file that tells the JSP pages where to find the servlets
And you need a server program that you can hand your project to so it can run.

And also, it looks like you're not using an Integrated Development Environment to do this? If you're not, I'd really recommend writing your code using an IDE. You*can* compile java from the command line like that, but it's so much easier to do with a program that's specifically designed to write, compile, and run code. If you're trying to do web stuff, I'd really recommend using the NetBeans IDE, which you can download here: https://netbeans.org/downloads/

Get the one with everything. It comes with Tomcat 8, which is a server that you can use, and it's built into the IDE so you don't have to worry about configuring too much of that yourself. Good luck!
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic