Link to home
Create AccountLog in
Avatar of dbaseek
dbaseek

asked on

jsp issue

How can we deploy and execute jsp..
after writing the code in ecclipse..eg I created a jsp named chapt2jsp.jsp under Chapt2
What are the further steps needed to see the output of application.
thanks
Avatar of Murali Murugesan
Murali Murugesan
Flag of Australia image

Step 1: You should have Tomcat or any other web server installed in ur machine. Since Tomcat is free i take that as example.So have Tomcat installed on ur machine.

Step 2: Create a java web project in you eclipse.So you will have structure something like below

 JspProject
|_ JavaSource - Create java classes for ur web application
|_ Webcontent
                      |_ WEB-INF - place ur web.xml
|_ Chapt2
              |_ Chapt2.jsp

     So now ur ready with the project structure, which u can deploy in tomcat.
Your web.xml should have this entry to access ur Chapt2.jsp by default.

<welcome-file-list>
        <welcome-file>Chapt2/Chapt2.jsp</welcome-file>
    </welcome-file-list>

Step 3: Place your project folder to Tomcat/webapps/(JspProject)

Step 4: Start tomcat and type the url in browser http://localhost:8080/JspProject/

You should see the Chapt2.jsp content displayed.

Note: Include the Servlet.jar and other required jars as required in ur eclipse.

-Murali*
Avatar of dbaseek
dbaseek

ASKER

let me try with a small application....
Chapt2 is my project ..In that project I created a a jsp file named Chapt2jsp.jsp
<HTML>
<BODY>
Hello!  The time is now <%= new java.util.Date() %>
</BODY>
</HTML>
In the webcontent folder  this is the web.xml
<?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>Chapt2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
Is this right or not
then what is the next step
Hope you created the project structure as i mentioned above.

Remove ur complete welcome file list and replace with this.

  <welcome-file-list>
    <welcome-file>Chapt2jsp.jsp</welcome-file>  -- this will work if you place the jsp in the root directory(Chapt2)
 </welcome-file-list>

If you have the .jsp somewhere in the folder inside WebContent, then do as below

  <welcome-file-list>
    <welcome-file>pages/Chapt2jsp.jsp</welcome-file>
 </welcome-file-list>

-deploy in tomcat and access with the specified url and you are good to go.

-Murali*
Avatar of dbaseek

ASKER

Mr Murali
What is "pages"  here.........it is means what.
<welcome-file-list>
    <welcome-file>pages/Chapt2jsp.jsp</welcome-file>
 </welcome-file-list>
pages - is a folder that you can create under webcontent folder. It need not be "pages" you can name anything as you wish. Point here is use the folder name in which u place ur jsp. For now don't confuse just have ur jsp file in the root directory. (i.e) Chapt2 - your project folder

-Murali*
Avatar of dbaseek

ASKER

Here is the new web.xml under webcontent ..
1,2,5 and 7  lines shows red curvley lines showing error: mouse over shows word correctly not spelled
Is this ok ?
--------------------------------------------------------
<?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>Chapt2</display-name>
  <welcome-file-list>
    <welcome-file>/Chapt2/Chapt2jsp.jsp</welcome-file>
     </welcome-file-list>
</web-app>
-------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">


replace ur top web-app tag with this.



moreover web.xml should be under ( WebContent/WEB-INF) folder and not directly under ( WebContent) folder.

It is better to try IDE such as Eclipse, Netbeans...

which reduce the time compile and deploy like these things...
Avatar of dbaseek

ASKER

Sorry one more question when we create Chapt2jsp.jsp it should be under  JavaResources:src  or webcontent...
Avatar of dbaseek

ASKER

The reason what I asked you  is
this is my jsp code:
<HTML>
<BODY>
Hello!  The time is now <%= new java.util.Date() %>
</BODY>
</HTML>
It is in Chapt2  folder ok
Now when I try to run the Chapt2jsp.jsp  this message is appearing  "cannot find main class program will exit"

What is the reason?
webcontent
Avatar of dbaseek

ASKER

If that is the case can you please tell me the reason of the error when I run..
the error is like this
Now when I try to run the Chapt2jsp.jsp  this message is appearing  "cannot find main class program will exit"
when you run java problem such error comes.
right click jsp and run/deploy on tomcat server
Avatar of dbaseek

ASKER

I changed the content of the file Chapt2jsp.jsp to the bottom
again same error   what is wrong.............
java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
      at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:54)
---------------------------------------------------------------------

<%@ page info="a hello world example" %>
<html>
<head><title>Hello, World</title></head>
<body bgcolor="#ffffff" background="background.gif">

<table>
<tr>
<td width=150> &nbsp; </td>
<td width=250 align=right> <h1>Hello, World!</h1> </td>
</tr>
</table>
</body>
</html>

Avatar of dbaseek

ASKER

This is the latest error report
--------------------------------------------------------------------------------

type Status report

message /Chapt2/Chapt2jsp

description The requested resource (/Chapt2/Chapt2jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.
ASKER CERTIFIED SOLUTION
Avatar of Murali Murugesan
Murali Murugesan
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Are you using any IDE?
how you are deploying ear to server?