netbeans text not allowed in element form error - java

I'm pretty new to HTML and trying to figure the following error:
I'm using netbeans (7.4) and I am trying to make a Web project with Servlets. When I use the defaults that we are instructed to use (yes it's a homework assignment, but my issue is ancillary to the actual assignment, so I don't think I'm trying to cheat here), Java 5 EE, it creates index.jsp. If I write HTML in that .jsp file, such as
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> <title>Foo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8084/MyProject/MyClass" method=GET>
How many Foos and Bars?
<select name="Foo">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select name="Bar">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
</body>
</html>
it works perfectly fine. However, we are told to use .html files instead of .jsp files, and when I copy this file over (from a .jsp to a .html), without the following line (which causes it's own error if included)
<%#page contentType="text/html" pageEncoding="UTF-8"%>
then Netbeans tells me:
"Text not allowed in element 'form' in this context"
So how do I get text in-between some of my form-fields, when it is an HTML document, not a .jsp?

Put your text inside <p> tags. Browsers are awfully forgiving (this HTML file works fine in Firefox), but free-floating text should be captured inside appropriate container elements (generally, <p>, <div>, or the HTML5 semantic elements).

Related

Spring Boot cant serve css file with Thymeleaf View

I am making an app with Spring Boot.
I have a Thymeleaf view chat.html in resources/templates/chat.html I include style.css stylesheet in it.
When I load the chat.html in browser only html shows without any stylesheet.
Here is chat.html
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link href="styles/style.css" rel="stylesheet">
<title>Chat Web App</title>
</head>
...some irrelevant html ...
<body>
</body>
</html>
I have put the style.css in resources/static/styles/style.css as per several other answers for same problem but no bueno. Perhaps some additional configuration need to be made or i am simply making a dumb typo.
The issue was actually in my CSS file :) . Apparently i had selectors for classes that werent present in the html. After removing them the solution proposed in the comments worked fine!

How can I export jsp to doc file?

I have to add a Button to a JSP to export the page in Word format (.doc or .docx).
I found How can we export jsp to doc file? but the link stackoverflow.com/questions/5946032/export-jsp-to-doc-fomat doesn't work anymore.
Do you have a simple example to solve my task or a working link?
Thanks in advance!
I found the indication of adding these two lines at the top of JSP, which seems to work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%# page language="java" contentType="application/msword; charset=windows-1252" %>
Thank you to help me to refine the searching !!

where and how to link html file,css file,javascript file and jsp

i have CSS file in one folder,html file in one folder,javascript in one folder. where shoul i link these files and how?whether in html or jsp page.please let me know.. even after giving a link like
where CSS is my folder.
how a proper aggregation is needed in in eclipse considering the industry standards ?
You link the files on your html page in the head of the document.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../css/main.css">
<script src="../js/main.js"></script>
</head>
...
Some people recommend linking javascript at the end of the document (just before the closing body tag) so that the visible elements can be rendered first before the javascript is parsed.
Just to clarify, css must be in the head; javascript can be anywhere and possibly/probably optimal at the end.
use link element to link various resources to your page like: CSS files, a favorite icon ...
check out this video demo
and script tag (as shown above by Crazysheep) to link scripts

No Sign of Applet Running from HTML

I put together a java ChatClient and ChatServer on Max OS X Version 10.7.5 for fun with my kids. We were using Java Version Java(TM) SE Runtime Environment (build 1.7.0_04-b21). It runs great from the Terminal. Also, we'd like to able to run it from Eclipse by passing in parameters.
When I open the HTML in Safari 6.0.2., I get no sign of errors or the applet running. In Safari, I have enable plug-ins, Java, and Javascript. Only the text in the HTML is displayed; the applet does not seem to run or anything.
Once I get this working, I would like to package in a JAR file and sign it so I can create a socket to my server. The applet is a simple guy that asks to connect via socket, then sends and receives text from any other clients including itself.
<Html>
<Head>
<Title>Java Example</Title>
</Head>
<Body>
This is my page<br>
Below you see an applet<br>
<br>
<Applet Code="ChatClient" width=200 Height=100>
<PARAM name="host" value="xxxxx-iMac.local">
<PARAM name="port" value="4445">
</Applet>
after Applet
</Body>
</Html>
In section 13.4, the APPLET tag in HTML is deprecated, and it's successor is the <object> element. You should think about a couple things here -
First, abide by HTML standards. This includes having all of your html tags and attributes in lowercase. <PascalCase>, <camelCase> are not standard for HTML.
Second, switch your applet tag to an object.
Thirdly, wrap all text in a block tag other than <body>. Most popular one is <p> meaning paragraph.
Fourthly, wrap ALL html attribute values in double quotes. example: width=200 should be width="200"
Fifthly, think about doing 2 spaced tabs when doing html. it's much cleaner :)
I could go on, but i could be here forever. Bottom line is, follow standards.
But to answer your question:
In the specification, it looks like it expects the file name. this includes ".class" at the end. Try,
<html>
<head>
<title>Java Applet Example</title>
</head>
<body>
<div id="container">
<applet code="ChatClient.class" width="200" height="100">
<param name="host" value="xxxxx-iMac.local" />
<param name="port" value="4445" />
</applet>
</div>
</body>
</html>

Display an applet in a webpage using HTML/JavaScript

I have very little experience with HTML and applets. I have tried several of the things I found online, but am unable to make my Java applet run in a web browser (it functions in eclipse).
I have put the HTML file in the same folder as all of my Java class files for the applet. I am currently using Safari, but would like the applet to work in most any popular browser.
How can I display a java applet on a webpage using HTML/JavaScript? Can anyone offer any tips/advice?
Below is my attempted HTML code.
Attempt 1:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
width="200" height="200"
type="application/x-java-applet;version=1.5.0"
pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>
Attempt 2:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200">
<PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html>
Try below code
<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
</APPLET>
OR
<object width="400" height="400" data="helloworld.class"></object>
Good Luck...
Use deployJava.js to write the applet element. The script is supported by Oracle, and will:
Check the user has the minimum required Java, prompting them to install if not, before..
Writing the object/embed or applet element as is best known for that browser.
Other notes:
Is it PendulumApplet.class or Applet1.class? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class.
The .class extension in the code attribute is tolerated, but not correct. The value should be a string representing the Fully Qualified Name of the class. E.G. javax.swing.JApplet as opposed to javax.swing.JApplet.class.
HTML element names should be all lower case (e.g. <html> as opposed to <Html>)
What output do you see in the Java console? When debugging applets in a browser, it is vital ensure the Java Control Panel is configured to pop open the console on discovering an applet (or JWS app.).
Although I have not done so myself, my Java textbook provides this outline for an embed:
<applet
code = "ClassName.class"
width = 250
height = 50
[archive = archivefile]
[vspace = vertical_margin]
[hspace = horz_margin]
[algin = applet_alignment]
[alt = alt_text]
>
</applet>
(Optional parameters in brackets)
I was having this SAME issue myself.
Using <applet code=""></applet> doesn't work, but <Applet> or <APPLET> seems to work.
Google Chrome and IE.

Categories