Results 1 to 9 of 9
- 11-29-2008, 06:05 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 40
- Rep Power
- 0
Placing java code/html pages on website host
I wanted to try something really simple. I placed my java code into my public_html folder along with a html page with the code:
and my Java code is:Java Code:<form action = "MyFirstServlet" method = get>
When I open the html page, nothing comes out though. Do I have to put the Java code in another location or something? It's supposed to display "My First Servlet, December 2008" right when I open the html page. Don't pay to much attention to the code, I picked this out of a textbook to have something to work with.Java Code:import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class MyFirstServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITTLE>My First Servlet</TITLE></HEAD>"); out.println("<BODY>"); out.println("<H1>My First Servlet, December 2008</H1>"); out.println("</BODY>"); out.println("</HTML>"); out.close(); } }
- 11-29-2008, 08:38 AM #2
It should print the html, several things could be at fault but it should display the html. To include the Java code, you can use <pre> tags, ther is also something called an iframe, which works well here to display the java code.
move to servlets....Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-29-2008, 08:53 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 40
- Rep Power
- 0
Well it's supposed to be a servlet. What should I do to make it show properly? In my school, I think tomcat was used but I don't see that in the webhost i'm using.
- 11-29-2008, 12:48 PM #4
The html code should be located in WebContent/WEB-INF folder
If you use 8080 port on your localhost and your project is called Site,so it should be like this:
You should also check web.xml file where you declare which file is loaded as a welcome file,for example your welcome file is called index.html,your web.xml should beJava Code:http://localhost:8080/Site/MyFirstServlet
Java Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Site</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>Last edited by serjant; 11-29-2008 at 12:51 PM.
- 11-29-2008, 08:16 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 40
- Rep Power
- 0
Damn it, I can't post images yet =/ I was going to show the webhost I use. Atm I only have a public_html folder being used. Do I make the WEB-INF folder inside the public_html folder or in the home folder outside public_html. I can probably email the company that hosts my website to find out the port number.
So the java files need to be in its own project folder and then use the form action to call it out? Same as above, does it go in the public_html folder or in the home folder outside public_html?
Thanks.
- 11-30-2008, 04:16 AM #6
Member
- Join Date
- Nov 2008
- Posts
- 40
- Rep Power
- 0
Forget my last post, I saw what you meant but I still need to figure out my port number. Still waiting on email response to company.
- 11-30-2008, 02:22 PM #7
port numbers
WEB-INF should be something that is part of and controlled by the server, you do not code WEB-INF either in the url nor in the code you write. It is a convention that all the mapping to WEB-INF occurs inside the server code, thus preventing access to that directory except by code running on the server.
You write and compile java code, placing it behind WEB-INF during ftp upload, the mapping to that code is facilitated by some xml but server is supposed to ( and will ) look there for execuatable java code, you just do not put that in the url that opens the interaction.
Port number is similar, let the server do the port stuff while it is running. I if you need to pass variables to the program, use GET name/value pairs, or use forms. You can get into port numbers if you are running locally and want to do some testing, the RFC for port numbers allows a wide range for development and testing:which is the fancy version. In general you may use any port number over 1024Java Code:/* The Dynamic and/or Private Ports are those from 49152 through 65535 * Source: http://www.iana.org/assignments/port-numbers * The port numbers are divided into three ranges: the Well Known Ports, * the Registered Ports, and the Dynamic and/or Private Ports. */
There is a powerful server in the sample docs, study it if you can. Some hosts block access to some port numbers due to undisciplined abuse by some traffic, that is not a concern unless you are doing advanced studies.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-30-2008, 03:54 PM #8
I recommend you to work with eclipse,create there Dynamic Web project which will automatically create all the said above stuff for you,configure the server in eclipse and done .Make Ant build for your project and run it.
- 11-30-2008, 04:31 PM #9
Similar Threads
-
How to download website (Get all link in website)
By finalmem in forum Advanced JavaReplies: 0Last Post: 11-12-2008, 08:43 AM -
Unable to connect to MySQL on another (unix) host from Eclipse on my windows host
By kairamr in forum EclipseReplies: 0Last Post: 10-31-2008, 07:07 PM -
How to add or code for 'Question and Answer' on product page of website
By 82rathi.angara in forum Advanced JavaReplies: 1Last Post: 08-29-2008, 01:54 PM -
Kode Java Website
By wsaryada in forum Reviews / AdvertisingReplies: 4Last Post: 01-18-2008, 09:16 PM -
Error with Sql 2000:java.net.NoRouteToHostException: No route to host: connect
By bbq in forum JDBCReplies: 0Last Post: 06-27-2007, 07:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks