Results 1 to 7 of 7
I am trying to figure out what I am doing wrong in Java. My JSP page is not working in Tomcat. I don't know if there is something wrong with ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-23-2012 #1Just Joined!
- Join Date
- Sep 2012
- Posts
- 10
Need help with first JSP page in Tomcat, new to Java
I am trying to figure out what I am doing wrong in Java. My JSP page is not working in Tomcat. I don't know if there is something wrong with the code or if it is Tomcat. I tried using a sample JSP page from the web and I am getting Hyper Text Transer Protocol 500 errors. ( can't abrieviate without getting an error that I am trying to post a link to another website) I am using Tomcat 6.0, I am not sure if the sample JSP page is old and now for Tomcat 6.0 I have to call a different set of commands to do the same thing? Or if the issue is with Tomcat. I am not sure if I also need to make a servlet in order for this to work, the web example didn't mention any server sided coding needing to be done so I assume I don't have to. I am completely new to Java.
Here is a sample JSP page that displays the date. Jsp pages will work in my browser if I encode them only in html and don't embed any java into the JSP page.
*** note there are some Hyper Text Transfer Protocol and 'at' tags I had to take out because for some reason the server is thinking I am trying to post links to other websites, when I am just trying to show the code. So including those tags in my code gives a red flag and I get the message I am forbidden to post links to other websites. So if there are obvious tags missing in my webpage code , you know why.Code:<{'at symbol'}%page contentType="" import="java.util.*" %> <Hyper Text Transer Protocol> <body> <p> </p> <div align=""> <table border="0" cellpadding="0" cellspacing ="0" width="460" bgcolor="#999999"> <tr> <td width="100%"><font size="6" color ="#800000"> Date Example</font></td> </tr> <tr> <td width="100%"><b> Current Date and time is: <font color="#0000ff"> <%= new java.util.Date() %> </font></b></td> </tr> </table> </center> </div> </body> </Hyper Text Transfer Protocol>
*** update: Java works in terminal. I tried compiling a general helloworld.java in javac and then executing helloworld in java and it worked fine. So I know java is installed and working the way it is suppose to.Last edited by Gizmo007; 09-23-2012 at 02:48 PM.
- 09-23-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,695
What does the Apache or Tomcat error log say?
Can you provide a link to the website where you are getting your sample and instructions from? To post it in the forum, just replace the "http" with "hxxp".
- 09-23-2012 #3Just Joined!
- Join Date
- May 2012
- Posts
- 43
HTTP is a networking protocol, you need HTML tags wrapped around the body.
- 09-24-2012 #4Just Joined!
- Join Date
- Sep 2012
- Posts
- 10
I have <hxxp></hxxp> tags wrapped around the body I can't put that on this forum because the server thinks I am referencing an external website and that is not allowed since I have less than 15 posts. This JSP page works fine if I load into my php directory and run it off of apache/php instead of directly through Tomcat
Here is a copy of the error I am getting
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
person.doGet(person.java:42)
person.doPost(person.java:49)
javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
root cause
java.lang.NullPointerException
org.apache.jsp.jsp.output_jsp._jspService(output_j sp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
person.doGet(person.java:42)
person.doPost(person.java:49)
javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
- 09-24-2012 #5Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,695
- 09-24-2012 #6Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,695
I got your (slightly modified) code to work for me. I called it "javatest.jsp" and put in a "document root" of a fake webapp in my tomcat base dir, e.g.:
I had previously created the above "hello" subdir when first testing out java/tomcat stuff.Code:cp javatest.jsp /var/lib/tomcat/webapps/hello/
Then i made sure tomcat was running:
(that's the systemd way of starting it...)Code:systemctl restart tomcat.service
Then I called the page in a URL like this:
Here is the code, for reference. I don't think the code is your problem, though (unless it is the very first include line). it is more likely that the file is just in the wrong place.Code:http://192.168.1.6:8080/hello/javatest.jsp
Code:<%@ page import="java.util.*" %> <html> <body> <p> </p> <div align=""> <table border="0" cellpadding="0" cellspacing ="0" width="460" bgcolor="#999999"> <tr> <td width="100%"><font size="6" color ="#800000"> Date Example</font></td> </tr> <tr> <td width="100%"><b> Current Date and time is: <font color="#0000ff"> <%= new java.util.Date() %> </font></b></td> </tr> </table> </center> </div> </body> </html>
- 09-24-2012 #7Just Joined!
- Join Date
- Sep 2012
- Posts
- 10
ok thanks ! I got my JSP pages working. A downside to installing all the add-on packages is there are so many config files to mess with in apache. I found one setting that was still set to localhost instead of 192.168.0.15 (my linux server address) and changed it to what it should be. Also when I copied the servlet-api.jar file to my ROOT directory in Tomcat then everything starting working fine for me. Thanks everyone for the help. Not sure how I fixed it it, but it's fixed. I appreciate the help thank you !




