Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder byuhobbes85's Avatar
    Join Date
    Oct 2006
    Location
    Ames, Iowa, USA
    Posts
    116
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Java Classes with JSP

    I am experienced with Java programming and server-side scripting with PHP/CGI, but I am trying to pick up JSP. I know that you can use Java classes in JSP servles, but I am really struggling to find tips on HOW to include those classes and WHERE to place those class files.

    Here is some code.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<title>JSP Test</title>
    		<%@ page import="java.util.*" %>
    		<%
    			Date date = new Date();
    			TestClass t = new TestClass();
    		%>
    	</head>
    	<body>
    		<h1>JSP Test</h1>
    		<%
    			out.println("<p>The current time is "+ date +"</p>");
    			out.println("<p>IP: "+ request.getRemoteHost() +"</p>");
    			out.println("<p>Test:"+ t.Test() +"</p>");
    		%>
    	</body>
    </html>
    I wrote and compiled a simple class called TestClass with two methods--a constructor (that does nothing) and the Test() method (which returns a string). Where should I put this class file and is there anything else I should know to make it work?

    Thanks!
    -- </byuhobbes>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    the compile class file should be in the WEB-INF/classes folder or if it is a jar then it should be placed in the WEB-INF/lib folder. add the necessary imports for your class and it should work fine
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder byuhobbes85's Avatar
    Join Date
    Oct 2006
    Location
    Ames, Iowa, USA
    Posts
    116
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Unhappy

    That is what I thought, but it's still not working. I just barely set up Tomcat before testing this. Is there any type of setting in Tomcat that I need to modify to enable this?
    -- </byuhobbes>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •