Netbeans IDE 15 Tomcat HTTP Status 404 - java

I am trying to build my first web application using Netbeans, with the tomcat server.
Here is my code for the html portion:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Unit Converter</title>
</head>
<body>
<div align="center">
<h1>Unit Conversion</h1>
<form action="convert" method="post">
Miles: <input type="number" name="miles" required />
<input type="submit" value="Convert to KM" />
</form>
</div>
</body>
</html>
Thats the entirety of my html code. Then I right-clicked on the project, made a servlet. Changed the Class name to something befitting the project. Location: source packages, and picked the default one for Package, then went to the next page(called configure servlet deployment)... left most of it the same, changed the URL pattern to /convert.
Then it makes the servlet, HTML page WORKS! The button on the html page gives that error before I even add my own code to java. I added my code to java and still error. I have built many times, ran many times.
Not sure what I am missing, I looked around and I may be missing a web.xml file but it never generates one for me.
Edit: Changing "convert" to "/convert" in the html file did not work :(
Edit2: Before posting, dont believe the "page" made by this post, my html code works.

Related

After inserting an image -> the Applet stop to work (there is just a gray box)

I read already a lot of topics like this or this on stack overflow without no luck.
So what is going on. I have an applet that I created in Netbeans. It works fine until I insert an image in it as icon. My os is MAC and I use Firefox.
In Netbeans the applet looks ok when I run it. The problem is that in Firefox I see just a gray BOX instead of my applet.
Does anyone have any idea what is going on here?
So my HTML file looks like that:
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="slipapplet/SlipApplet.class" width=880 height=650 archive="/Users/Serial/NetBeansProjects/SlipApplet/build/classes/slipapplet/swing-layout-1.0.4.jar,/Users/Serial/NetBeansProjects/SlipApplet/build/classes/slipapplet/AbsoluteLayout.jar"></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
This is code about the label with icon in java:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Users/Serial/NetBeansProjects/SlipApplet/src/slipapplet/kemp.jpg")));
And the HTML file is in an upper file then everything else..

Java Applet works in Firefox only

I have implemented a Java Applet.
I have exported the jar.
I signed the jar.
And it works if I put it on my server and use it with HTML.
But only in Firefox.
Here is the HTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Upload Test</title>
</head>
<body>
<object archive="applet.jar" classid="java:uploader/FileUpload.class"
codetype="application/java-vm" width="800" height="600"> </object>
</body>
</html>
I also tried it with this:
<SCRIPT type="text/javascript">
if(browser.value.getIndex("chrome") {
chrome.browser.enableFeature(JApplet)
});
</SCRIPT>
But still Firefox only.
I would really like for this to work in Chrome & IE9.
But these two only leave a space where the Applet should be.
I can even highlight it.
Are there things I have to add in my xhtml? Or maybe something in the Applet?
I found enough online about why Applets might not work, but nothing about why Firefox only.
As Andrew Thompson said, I need to use deployJava.js.
You can find it in this Oracle tutorial.
This tutorial describes in detail every step neccessary.
Now my Applet works on all three browsers (FF, Chrome, IE9) like a charm.
Thanks!

Is there a way to run a JSF page without building the whole project?

Is there a way to just run the one page so that I can see the generated html (and css) as it would look to the user even if it is essentially non-functional? Standalone JSF page as it were. I want to review how I am setting up forms to see if they make sense form a user standpoint before actually coding for the form's fields. I'm using maven and netbeans but not sure if the latter is relevant.
If you're using JSF2 Facelets, then you can just design your forms with plain HTML and use the jsfc attribute to specify the respective JSF component which should be used during JSF runtime. E.g.
<form jsfc="h:form">
<label jsfc="h:outputLabel" for="input1" />
<input type="text" jsfc="h:inputText" id="input1" value="#{bean.input1}" required="true" />
<span jsfc="h:message" for="input1" />
<input type="submit" jsfc="h:commandButton" value="Submit" action="#{bean.submit}" />
</form>
Reading the Facelets <ui:xxx> taglib documentation should also give some insights. E.g.
<span jsfc="ui:remove">
This is present during design time, but is removed during JSF runtime.
</span>
<div jsfc="ui:repeat" value="#{bean.items}" var="item">#{item}</div>
<table>
<tr jsfc="ui:repeat" value="#{bean.items}" var="item">
<td>#{item.id}</td>
<td>#{item.name}</td>
</tr>
</table>
And the fact that you can use <ui:composition> to specify the start and end of a Facelet composition (e.g. an include file or a tag file). Any content outside will be disregarded during runtime, but you can still put some HTML around during designtime so that you can easily preview complete designs in which the include file or tag file is supposed to be part of.
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<head>
...
</head>
<body>
...
<ui:composition>
Here you can design content of include file or
tag file as if it's part of the whole design.
</ui:composition>
...
</body>
</html>
This all allows you to preview HTML/CSS designs without needing a JSF runtime.
JBoss Tools for Eclipse have rudimentary support for JSF-tags in their visual editor.
I played briefly with it, but it did not support our legacy pages fully, so I left it at that. It may work better when starting with a blank page.
You can not execute a JSF page directly without deploying the built application. You have to deploy it, and only then will you be able to display executed the page.

How do I embed a java swing applet into a website?

I am trying to embed a swing applet into our website, but it is not working. I have been able to get applets that use awt to do graphics to work. The web page that contains the applet only shows a blank box that should contain my applet, there aren't even any error messages. My applet works fine in netbeans. The applet is supposed to show a few buttons and a text field. I really don't know whats going on.
The web page is located at http://nuevawave.org/sandbox/JavaGallery/GUIApplet.html
The applet is at http://nuevawave.org/sandbox/JavaGallery/TestApplet.jar
Here is the html:
<html>
<head>
<title>Test Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<applet Archive ="TestApplet.jar, swing-layout-1.0.4.jar"
Code="test.GUIApplet"
WIDTH="250" HEIGHT="300" >
</applet>
</body>
</html>
as I wrote in the comments it works for me (I'm using OpenJDK 1.6.0_22, Linux (ubuntu) and Firefox).
If java works from your "command line" or terminal. I could be that the plugin for your browser isn't installed. I would recommend you reinstalling the JDK or JRE and remember to install the plugin for the browser aswell.
You can use the <object> tag instead. To know how to use this, check this link

JFileChooser pop up 2 times

This is my JSP file.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
//JFileChooser filechoose = new JFileChooser();
JFileChooser filechoose = new JFileChooser("D:\\");
filechoose.showOpenDialog(null);
File file = filechoose.getSelectedFile();
XLCauHoi.ImportXmlFileToData(file);
%>
<h4> Đã xuất file thành công </h4>
</body>
</html>
My problem is that: the JFileChooser pops up 2 times when I run it on browser. If I run it in a Java class, JFileChooser pops up 1 time.
What is my problem and how to solve it?
There's a major misconception here. First thing, JSP/Java runs at the webserver, produces a bunch of HTML/CSS/JS and sends it to webbrowser. Webbrowser retireves HTML/CSS/JS and interprets/applies/executes it. It doesn't run any line of Java code because it has already been executed on the webserver. Rightclick page in webbrowser and choose View Source. Do you see it? If webserver has done its job right, you should not see any line of Java code in there. The webbrowser namely doesn't understand it. It only understands HTML/CSS/JS.
Using a JFileChooser in a JSP scriptlet would technically only "work" when both the webserver and webbrowser runs at physically the same machine. It's basically the webserver which displays the dialog, not the webbrowser. This would only "work" when you're locally developing, but never when you publish the website into world wide web by a standalone webserver.
To upload files by HTML, you need an <input type="file"> element, not a JFileChooser. For more detail how to use it with JSP/Servlet, check this answer.
As to the concrete problem, I have no idea why it pops 2 times, but that should be your least concern in this particular case.

Categories

Resources