JSP calling servlet, servlet in a package!

Hi,
I have two servlets called
1- (myPackage.MyServlet)
2- MyServlet2
Using a button in an HTML page, how can I direct the call to the servlet packaged servlet??
when I call MyServlet2, everything is fine:
<form method="POST" action="/MyServlet2" name="addUserForm1">when I call myPackage.MyServlet a resource not found Error appears.
<form method="POST" action="/myPackage.MyServlet" name="addUserForm1">I am using Netbeans, Tomcat server 5.5.7

Answers can be found in this tutorial: http://www.coreservlets.com/Apache-Tomcat-Tutorial/#Web-Apps
I would guess that something like this is called for
     <?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">
       <servlet>
          <servlet-name>Servlet2</servlet-name>
          <servlet-class>coreservlets.HelloServlet2</servlet-class>
       </servlet>
       <servlet-mapping>
          <servlet-name>Servlet2</servlet-name>
          <url-pattern>/servlet2</url-pattern>
       </servlet-mapping>
     </web-app>

Similar Messages

  • Jsp calls servlet

    hi,
    could you please help me with this problem:
    i use tomcat 5.5,
    here're my folders and files in the root folder cns(cns in tomcat\webapps\):
    cns\registration.jsp
    cns\WEB-INF\classes\servlet\RegistrationServlet.java (and .class)
    here is the form in registration:
    <form action="/cns/WEB-INF/classes/servlet/servlet.RegistrationServlet" method="post">
    <td><input type="submit" value="submit"></td>
    </form>
    and here is the content of RegistrationServlet.java file:
    package servlet1;
    class RegistrationServlet extends HttpServlet{
    but when i click the "submit button", tomcat returns an error page:
    HTTP Status 404 - /cns/WEB-INF/classes/servlet/servlet.RegistrationServlet
    type Status report
    message /cns/WEB-INF/classes/servlet/servlet.RegistrationServlet
    description The requested resource (/cns/WEB-INF/classes/servlet/servlet.RegistrationServlet) is not available.
    i have tried to modify the relative link in the <form action="..."> but no effects.
    :(

    hi,
    could you please help me with this problem:
    i use tomcat 5.5,
    here're my folders and files in the root folder
    cns(cns in tomcat\webapps\):
    cns\registration.jsp
    cns\WEB-INF\classes\servlet\RegistrationServlet.java
    (and .class)
    here is the form in registration:
    <form
    action="/cns/WEB-INF/classes/servlet/servlet.Registrat
    ionServlet" method="post">
    <td><input type="submit"
    value="submit"></td>
    /form>
    and here is the content of RegistrationServlet.java
    file:
    package servlet1;
    class RegistrationServlet extends HttpServlet{
    but when i click the "submit button", tomcat returns
    an error page:
    HTTP Status 404 -
    /cns/WEB-INF/classes/servlet/servlet.RegistrationServl
    et
    type Status report
    message
    /cns/WEB-INF/classes/servlet/servlet.RegistrationServl
    et
    description The requested resource
    (/cns/WEB-INF/classes/servlet/servlet.RegistrationServ
    let) is not available.
    i have tried to modify the relative link in the <form
    action="..."> but no effects.
    Here is the code u can copy and use it:
    login.jsp
    <html>
    <head>
    <title>Test JSP</title>
    </head>
    <body>
    <form action="./register" method="post" >
    <br>
    <input type="submit" value="Test OK" >
    </form>
    </body>
    </html>place above JSP file in your root directory (cns).
    RegistrationServlet.java
    package servlet;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    * @author sivakumar
    public class RegistrationServlet extends HttpServlet  {
          public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
                   PrintWriter out=response.getWriter();
                   response.setContentType("text/html");
                   out.println("Hi this is my servlet");
    }compile the above Servlet and put the class file in classes directory of WEB-INF
    then ur direcotry structure should be like as follows:
       cns
            WEB-INF
                      classes
                              servlet
                                      RegistrationServlet.class
                      lib
                      web.xml
             login.jspin the above structure "servlet" is the package which contains RegistrationServlet.class file. make sure that u create the package.
    and web.xml file should be like this;
    <?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">
      <servlet>
        <servlet-name>registration</servlet-name>
        <servlet-class>servlet.RegistrationServlet</servlet-class>
      </servlet>
      <!-- Standard Action Servlet Mapping -->
      <servlet-mapping>
        <servlet-name>registration</servlet-name>
        <url-pattern>/register</url-pattern>
      </servlet-mapping>
    </web-app>Now give the url
    http://localhost:8080/cns/login.jsp

  • Not able to call servlet from jsp

    I have a jsp from which i'm calling a servlet code is given below:-
    <html>
    <body>
    <jsp:forward page="/doubleHello" />
    </body>
    </html>
    my web.xml is:-
    <web-app>
    <display-name>HelloServlet</display-name>
    <description> HelloServlet </description>
    <servlet>
    <servlet-name> ServletCallingEjb </servlet-name>
    <servlet-class> myServlet.HelloServlet </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> ServletCallingEjb </servlet-name>
    <url-pattern> /doubleHello </url-pattern>
    </servlet-mapping>
    </web-app>
    My servlet looks like:-
    package myServlet;
    import myEjb.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class HelloServlet extends HttpServlet
    public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
         out.println("<html><head><title>Hello from Servlet</title></head>");
         out.println("<body><h1>Hello from hello servlet!</h1></body>");
    out.println("<br>";
    out.println("</html>");
    But when i run the code i'm getting page cannot be displayed. Please please suggest what am i doing wrong???
    Message was edited by:
    Samrat Kar

    Reframing the question
    I have a jsp from which i'm calling a servlet code is given below:-
    <html>
    <body>
    <jsp:forward page="/doubleHello" />
    </body>
    </html>
    my web.xml is:-
    <web-app>
    <display-name>HelloServlet</display-name>
    <description> HelloServlet </description>
    <servlet>
    <servlet-name> ServletCallingEjb </servlet-name>
    <servlet-class> myServlet.HelloServlet </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> ServletCallingEjb </servlet-name>
    <url-pattern> /doubleHello </url-pattern>
    </servlet-mapping>
    </web-app>
    My servlet looks like:-
    package myServlet;
    import myEjb.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class HelloServlet extends HttpServlet
    public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter(); out.println("<html><head><title>Hello from Servlet</title></head>");
    out.println("<body>Hello from hello servlet!</body>");
    out.println("</html>"); } }
    But when i run the code i'm getting page cannot be displayed. Please please suggest what am i doing wrong???

  • How to call my own class in package B from a servlet in package A?

    Hi, I am trying to call a class in my serlvet, but the class is in a different package than my servlet, i.e., my servlet is in package A, and the class my servlet calls is in package B. I created a .jar for all files in package B, put the jar file in %JAVA_HOME%/jre/lib/ext, and set classpath to %JAVA_HOME%/jre/lib/ext. I can compile my servlet, but when I run it with Tomcat 4.0, it says that the class in package B is not defined (NoClassDefinitionError).
    Can anyone help? Thanks a lot.

    I set JAVA_HOME to c:\j2sdk1.4.0.
    All classes in package B are in one jar file, and all classes in package A are under CATALINA_HOME\webapps\ROOT\WEB-INF\classes. Do I need to create another jar file for package A or should I put package A in the same jar file as package B?
    I tried to put the jar file under WEB-INF\lib, but it still failed.
    The project is the first time for me to use servlet, so I am not very familiar with it. I am wondering if there is any configuration file I need to modify for the servlet I wrote?
    Thanks for the help.

  • Wot all ways are there to call servlet from jsp

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanx

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanxhi here are few ways... to call servlet from jsp...
    these are just generic syntax.
    Form:     
    <form action="ServletPath">
    Link:     
    Directives & Action tags :
    <%@ page import="ServletPath" %>
         <%@ taglib uri="ServletPth" %>
         <jsp:include page="ServletPath">
         <jsp:forward page="ServletPath">
         <jsp:useBean class="ServletPath"> (Not sure about this useBean)
    hope you got your answer.
    regards,
    immu

  • Hi everybody, JSP+servlets+.exe execution+package problem

    hi, i've read on java's forums that it is possible to execute an external class from a JSP and this (external class) can execute an .exe(Runtime a = Runtime.getRuntime()) i don't know if it was developed with JSP or servlet because they didn't put the code but it's factible, another question is if its necessary to package all clases to use some of them (1 class or 2) in a JSP?, or Can i just use one class with a main() executed by a servlet says?. last i've want to know if it's possible to communicate a servlet and a JSP and viceversa, i would apretiate much your help, thanks.

    please type a new empty line after each question.
    do your research on the internet with Google.
    learn the basics with a tutorial.

  • Maintain session when calling servlet from form in a JSP

    I have the following set up:
    index.jsp calls login servlet from the action tag in a form.
    Login servlet handles the login, stores the user info and db connection in the session and uses forward(req,res) to call another jsp.
    That jsp has a form where user enters search info and in that form's action tag there is a search servlet. In the search servlet I am unable to access the session.
    Is there any way to pass the session to the servlet from that jsp using a form/action?

    I've read elsewhere that if you go from a jsp to a servlet that the >request object is cleared of any attributes from the previous request.which is correct. But arent we speaking about session object here? A request object is valid for a request - ie the phase from where the server receieves a hit for a resource upto the point it sends the output for that request.
    A session spans multiple requests.
    it doesn't retrieve the session info and gives me a null pointer >exception when I try to use the connection object stored in the session.Bad bad bad . Why do you store Connection objects in session? Create them when necessary or use a connection pool. Do you for example clean up the connections when the session expires. What if its a 30 minute session and the user hits every say 15 minutes with a request. Why do you need to hold on to the Connection in the intervening interval when the user's session is inactive?
    gives me a null pointer exception when I try to use the connection object stored in the session.which means that the Connection object is null - not the session object.
    That last line is where I get the null pointer exception. And that is
    Statement stmt = con.createStatement();?
    Same answer as above.
    If the session object was null,
    userSession.getAttribute("connection");would have thrown a NPE.
    ram.

  • Jsp file calling servlet two times

    hello
    i have created registration form for hospital management project in which registration form is jsp file on clicking on submit it calls servlet file which actually inserts data into database but problem is when i click on submit button it calls servlet file more than one time which leads to duplication of data.plz help in this matter, It is very important to me

    First question is are you absolutely sure that the form is being submitted twice? Did you look at the access logs to see that there are two Http requests being sent to the server?
    In tomcat you have to enable the access logs.

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • Deploying a WAR file containing .jsp and servlets (also uses JNI)

    Deploying a WAR file containing .jsp and servlets (also uses JNI) on Windows 2000
    We had problems making it initially work on Sun ONE Web Server 6.0 Service Pack 1 because of lack of good iPlanet Web
    Server documentation on deploying such files.
    This is how we went about it:
    1) Make one of the servlet and JSP (must call another Java Class) web application (.war) examples work with iPlanet Web
    Server.
    C:\iPlanet\Servers\plugins\servlets\examples\web-apps\HelloWorld\HelloWorld.war
    and
    C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
    a) Go to your Web Server Administration to deploy the application using GUI Web Application Deploy.
    (We usually use command line, we experienced some issues with the GUI version, but maybe it is fixed in the new Web Server
    service packs)
    From browser, open http://yourserver:8888/
    Click on Select a Server:Manage
    Click on Virtual Server Class
    Click on https-yourserver
    Click on the Web Applications Tab
    Then, click on Deploy Web Application
    Enter the following -
    WAR File On: Local
    WAR File Path: C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
    Application URI: /jakarta
    Installation Directory: c:\iPlanet\examples\jakarta-examples
    By clicking on OK it deployed the application.
    I can verify that it is deployed by selecting "Edit Web Applications" and I see the following entry:
    Edit     /jakarta     c:/iPlanet/examples/jakarta-examples
    Also, c:/iPlanet/examples/jakarta-examples should have the similar following directory structure ..
    - [images]
    - [jsp]
    - index.html
    - [servlets]
    - [META-INF]
    - [WEB-INF]
    - [classes]
    - [tlds]
    - web.xml
    - index.html
    I restarted the server and accessed it using the following URL from my IE browser:
    http://yourserver/jakarta/index.html
    Then I clicked on the JSP Examples and tried some JSP examples.
    b) Alternatively, you can also deploy the same example from the command-line.
    Make sure C:\iPlanet\Servers\bin\https\httpadmin\bin\ is in your path
    wdeploy deploy      -u /jakarta
              -i yourserver
              -v https-yourserver
              -d c:\iplanet\examples\jakarta-examples
              C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
    Restart the web server (I don't think you have to restart, but .. might as well).
    2)Deploy your web-application
    My Foo.war has the following structure.
    You can use jar tf Foo.war to look at the file contents from command line (assuming you have JDK installed and the bin is
    in your PATH)
    Foo.war
    - [META-INF]
    - [WEB-INF]
    - web.xml
    - [classes]
    - Bar.class
    - MoServlet.class
    - [lib]
    - ThirdParty.jar
    - [natlib]
    - extlib.dll
    - foo.jsp
    Here is our application scenario:
    foo.jsp uses a class call Bar (it is not in any package). The Bar java class uses classes from ThirdParty.jar. The
    ThirdParty.jar in turn uses JNI to load library extlib.dll. foo.jsp also calls /servlet/Mo as well.
    Now to deploy it, do the following:
    (a) Make sure that within foo.jsp, you import the Bar class ( I don't know why you have to do it, but if you don't you get
    JSP compile error).
    <%@page language="java" import="Bar" contentType="text/html"%>
    (b) Check web.xml (for Servlets)
    Within web.xml, make sure you have the following mappings:
    <servlet>
    <servlet-name> MoLink </servlet-name>
    <servlet-class> MoServlet </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> MoLink </servlet-name>
    <url-pattern> /servlet/Mo </url-pattern>
    </servlet-mapping>
    (c) Deploy the application
    Using command line:
    wdeploy deploy      -u /foo
              -i yourserver
              -v https-yourserver
              -d c:\iplanet\examples\foo-dir
              Foo.war
    (d) Change web-apps.xml file (for picking up ThirdParty.jar)
    It is located in
    C:\iPlanet\Servers\https-yourserver\config
    You should see something similar to following after successful deployment.
    <web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true"/>
    Change it to look like following to pick up the ThirdParty.jar
    <web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true">
    <class-loader reload-interval="300"
              classpath="C:/iPlanet/examples/foo-dir/WEB-INF/lib/ThirdParty.jar"
              delegate="false"/>
    </web-app>
    (e) Change jvm12.conf file (for JNI)
    It is located in
    C:\iPlanet\Servers\https-yourserver\config
    Add or uncomment the following lines:
    #optional - just helps with instrumenting the jsp and servlet code
    jvm.include.CLASSPATH=1
    jvm.enableDebug=1
    nes.jsp.enabledebug=1
    jvm.trace=7
    jvm.verboseMode=1
    #required for JNI
    java.compiler=NONE
    jvm.classpath=.;C:\JDK1.3.1\lib\tools.jar;C:/iPlanet/Servers/plugins/servlets/examples/legacy/beans.10/SDKBeans10.jar;
    jvm.option=-Xrs
    jvm.option=-Xnoagent
    # not sure if this is needed for iPlanet web server
    jvm.option=-Djava.library.path=C:/iPlanet/examples/foo-dir/natlib/ -Djava.compiler=NONE
    (f) Change magnus.conf file (for JNI)
    We HAD to change this file in order for ThirdParty.jar file to pick up the native C++ code using JNI. Apparently, the
    iPlanet Web Server doesn't pick the Environment Variable Path. Because when we had the directory containing the DLL just
    in Path, it didn't work.
    Change Extrapath directive:
    ExtraPath C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
    to
    ExtraPath c:/iPlanet/examples/foo-dir/natlib;C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
    (g) Apply changes from the Web Server Administration Console and Restart the web server.
    You should be able to see the behaviour that you want from your application.
    http://yourserver/foo/foo.jsp
    Hope this was helpful!!!
    Sonu

    Deploying a WAR file containing .jsp and servlets (also uses JNI) on Windows 2000
    We had problems making it initially work on Sun ONE Web Server 6.0 Service Pack 1 because of lack of good iPlanet Web
    Server documentation on deploying such files.
    This is how we went about it:
    1) Make one of the servlet and JSP (must call another Java Class) web application (.war) examples work with iPlanet Web
    Server.
    C:\iPlanet\Servers\plugins\servlets\examples\web-apps\HelloWorld\HelloWorld.war
    and
    C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
    a) Go to your Web Server Administration to deploy the application using GUI Web Application Deploy.
    (We usually use command line, we experienced some issues with the GUI version, but maybe it is fixed in the new Web Server
    service packs)
    From browser, open http://yourserver:8888/
    Click on Select a Server:Manage
    Click on Virtual Server Class
    Click on https-yourserver
    Click on the Web Applications Tab
    Then, click on Deploy Web Application
    Enter the following -
    WAR File On: Local
    WAR File Path: C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
    Application URI: /jakarta
    Installation Directory: c:\iPlanet\examples\jakarta-examples
    By clicking on OK it deployed the application.
    I can verify that it is deployed by selecting "Edit Web Applications" and I see the following entry:
    Edit     /jakarta     c:/iPlanet/examples/jakarta-examples
    Also, c:/iPlanet/examples/jakarta-examples should have the similar following directory structure ..
    - [images]
    - [jsp]
    - index.html
    - [servlets]
    - [META-INF]
    - [WEB-INF]
    - [classes]
    - [tlds]
    - web.xml
    - index.html
    I restarted the server and accessed it using the following URL from my IE browser:
    http://yourserver/jakarta/index.html
    Then I clicked on the JSP Examples and tried some JSP examples.
    b) Alternatively, you can also deploy the same example from the command-line.
    Make sure C:\iPlanet\Servers\bin\https\httpadmin\bin\ is in your path
    wdeploy deploy      -u /jakarta
              -i yourserver
              -v https-yourserver
              -d c:\iplanet\examples\jakarta-examples
              C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
    Restart the web server (I don't think you have to restart, but .. might as well).
    2)Deploy your web-application
    My Foo.war has the following structure.
    You can use jar tf Foo.war to look at the file contents from command line (assuming you have JDK installed and the bin is
    in your PATH)
    Foo.war
    - [META-INF]
    - [WEB-INF]
    - web.xml
    - [classes]
    - Bar.class
    - MoServlet.class
    - [lib]
    - ThirdParty.jar
    - [natlib]
    - extlib.dll
    - foo.jsp
    Here is our application scenario:
    foo.jsp uses a class call Bar (it is not in any package). The Bar java class uses classes from ThirdParty.jar. The
    ThirdParty.jar in turn uses JNI to load library extlib.dll. foo.jsp also calls /servlet/Mo as well.
    Now to deploy it, do the following:
    (a) Make sure that within foo.jsp, you import the Bar class ( I don't know why you have to do it, but if you don't you get
    JSP compile error).
    <%@page language="java" import="Bar" contentType="text/html"%>
    (b) Check web.xml (for Servlets)
    Within web.xml, make sure you have the following mappings:
    <servlet>
    <servlet-name> MoLink </servlet-name>
    <servlet-class> MoServlet </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> MoLink </servlet-name>
    <url-pattern> /servlet/Mo </url-pattern>
    </servlet-mapping>
    (c) Deploy the application
    Using command line:
    wdeploy deploy      -u /foo
              -i yourserver
              -v https-yourserver
              -d c:\iplanet\examples\foo-dir
              Foo.war
    (d) Change web-apps.xml file (for picking up ThirdParty.jar)
    It is located in
    C:\iPlanet\Servers\https-yourserver\config
    You should see something similar to following after successful deployment.
    <web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true"/>
    Change it to look like following to pick up the ThirdParty.jar
    <web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true">
    <class-loader reload-interval="300"
              classpath="C:/iPlanet/examples/foo-dir/WEB-INF/lib/ThirdParty.jar"
              delegate="false"/>
    </web-app>
    (e) Change jvm12.conf file (for JNI)
    It is located in
    C:\iPlanet\Servers\https-yourserver\config
    Add or uncomment the following lines:
    #optional - just helps with instrumenting the jsp and servlet code
    jvm.include.CLASSPATH=1
    jvm.enableDebug=1
    nes.jsp.enabledebug=1
    jvm.trace=7
    jvm.verboseMode=1
    #required for JNI
    java.compiler=NONE
    jvm.classpath=.;C:\JDK1.3.1\lib\tools.jar;C:/iPlanet/Servers/plugins/servlets/examples/legacy/beans.10/SDKBeans10.jar;
    jvm.option=-Xrs
    jvm.option=-Xnoagent
    # not sure if this is needed for iPlanet web server
    jvm.option=-Djava.library.path=C:/iPlanet/examples/foo-dir/natlib/ -Djava.compiler=NONE
    (f) Change magnus.conf file (for JNI)
    We HAD to change this file in order for ThirdParty.jar file to pick up the native C++ code using JNI. Apparently, the
    iPlanet Web Server doesn't pick the Environment Variable Path. Because when we had the directory containing the DLL just
    in Path, it didn't work.
    Change Extrapath directive:
    ExtraPath C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
    to
    ExtraPath c:/iPlanet/examples/foo-dir/natlib;C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
    (g) Apply changes from the Web Server Administration Console and Restart the web server.
    You should be able to see the behaviour that you want from your application.
    http://yourserver/foo/foo.jsp
    Hope this was helpful!!!
    Sonu

  • Getting to next JSP from Servlet

    I am getting a 404 when I try to redirect from my servlet to an error page. The code that I am testing is....
    catch (SQLException es)
    LOG.error("Unexpected error in Login.createUser.Error
    message = " + es);
    session.setAttribute(Constants.MESSAGE, es.getMessage());
    session.setAttribute(Constants.ERROR_TITLE, "Login error: " + Constants.SQL_ERROR);
    resp.sendRedirect(Constants.ERROR_PATH);
    I have a compiled java class called Constants where the ERROR_PATH is defined as
    /** Constant name used in obtaining the path to the error page. */
    public static final String ERROR_PATH = "/Jsp/error.jsp";
    My JSP pages are located at the root...
    myapp
    ....Jsp
    ....WEB-INF
    ........classes
    My web.xml looks like this
    <servlet>
    <servlet-name>errorPage</servlet-name>
    <jsp-file>/Jsp/errorPage.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
    <servlet-name>error</servlet-name>
    <url-pattern>/Jsp/error.jsp</url-pattern>
    </servlet-mapping>
    Can anyone point me in the right direction....Thanks

    I tend to use a utility method called redirectToResource in particular to redirect from any servlet to any JSP :
    /** This method will still work when the server is configured to
    *   listen to  port 80 rather than port 8080 (default in Tomcat)
    public void redirectToResource (HttpServletRequest req,
                                     HttpServletResponse resp,
                                  String resourceName)
                         throws ServletException, IOException
       int serverPort    = req.getServerPort();
       String scheme     = req.getScheme();
       String serverName = req.getServerName();
       StringBuffer urlBuffer = new StringBuffer(40);
       urlBuffer.append(scheme + "://" + serverName);
       urlBuffer.append(":" + serverPort);
       urlBuffer.append(resourceName);
        String location = resp.encodeRedirectURL(urlBuffer.toString());
        resp.sendRedirect(location);
    }

  • Need help in JSP and Servlets

    Hi friends,
    [please forgive me if i am posting this in the wrong forum, all seems same to a fresher]
    Now, to my problem..i need a suggestion, a way or a method to implement the following!
    I am supposed to create a servlet that reads data from oracle database. Once i retrive the data (for example: 6 rows of a table having 4 attributes), i am supposed to pass this data to a JSP page where the data has to be formatted and displayed properly. If i call the same servlet from a different JSP, i should be able to access the data in that JSP and format it in a different way. How do i pass the data to JSP? what method i can use to achieve this task?
    Note: I already know about PrintWriter pw = response.getWriter(); and then printing the formated HTML page..but i want to keep the formatting to JSP part and send only the data part that i can access in JSP
    Thanks in adavance

    arun_ramachandran wrote:
    [please forgive me if i am posting this in the wrong forum, all seems same to a fresher]Then you should learn to be more observant - after all, we have JSP and Servlet fora, further down the list. :)
    I am supposed to create a servlet that reads data from oracle database. Once i retrive the data (for example: 6 rows of a table having 4 attributes), i am supposed to pass this data to a JSP page where the data has to be formatted and displayed properly. If i call the same servlet from a different JSP, i should be able to access the data in that JSP and format it in a different way. How do i pass the data to JSP? what method i can use to achieve this task? You can store the data in your session object. You can even use JavaBeans and the jsp:usebean tag.
    [http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html]
    Note: I already know about PrintWriter pw = response.getWriter(); and then printing the formated HTML page..but i want to keep the formatting to JSP part and send only the data part that i can access in JSPA wise approach - I wish more prople woiuld be as thoughtful.

  • Calling servlet from a java program

    Hi
    I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
    Can anyone help me to start with this.
    any suggestion is welcome.

    You have to establish a URLConnection with servlet from your java program.
    URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
    URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
    ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
    oos.writeObject(your file object);-------------------------------------------------
    In the servlet u can get the strings using request.getParameter("str1");
    In the servlet u can get the strings using request.getParameter("str2");
    file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
    hope this helps :)

  • JSP and Servlets? What's the difference?

    I've got this book, and it's mixing servlet with jsp and then jsp with servlet. Can we just use one and still make a web application? What is the difference between the both? Can anyone give me a basic idea behind these 2 J2ee technologies.

    hi,
    Both use server-side Java to dynamically generate web pages. The source code to a JSP looks like HTML, with Java embedded inside
    (a) normal HTML tags, (b) JSP tags like <jsp:include>, (c) custom tags, (d) scriptlets (Java code surrounded with <% and %>).
    The source code to a servlet looks like Java, with HTML embedded in out.print(...) statements. Both use the Servlet API to communicate with the web server and the client. In fact, a JSP gets compiled into a servlet, so they're almost identical in terms of expressive power. The choice is, whether you're more comfortable coding your pages in Java or in JSP-style HTML; and since you can call a JSP from a Servlet and vice versa, you don't have to make an either-or decision.
    Karthick PalaniChamy

  • Basic jsp and servlet question (JSP Model 2)

    Hi
    I want to make an website where i use JSP Model 2 architecture. However I got a basic question
    1. I need to separate business logic from presentation with the use of jsp and servlets. Meaning I want no html code in the servlet. Can you give a simple example of how this can be done? If I map my implementation of httpServlet to a jsp page in web.xml and override doPost() and doGet(). The calls to the jsp page comes to the servlet as it should. I want to process some methods (calling sessionbeans or similar which in turn calls entitybeans) and then show the jsp page.
    How do I show the jsp page without mixing html in the servlet as I've done below:
    doGet(HttpServletRequest req, HttpServletResponse res)
    PrintWriter p = response.getWriter();
    p.print("<html><body>Hello world</body></html>"); //I dont want to do //this, I want to display the JSP site
    doPost(HttpServletRequest req, HttpServletResponse res)
    //doSomething
    }Message was edited by:
    CbbLe

    You should treat your servlet class much like a controller, where you can then use JSP as the view. The way you achieve this is to use the forward() method in RequestDispatcher.
    Say you've got a servlet class org.yoursite.controller.YourController:
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      //Set some value for use in the JSP file associated wth me
      req.setAttribute("greeting", "Hello world!");
      //Done with our business logic, off we go to the JSP file
      ServletContext app = getServletContext();
        RequestDispatcher disp;
        disp = app.getRequestDispatcher("/some/jsp/file.jsp);
        disp.forward(req, resp);
    }Now in your JSP file:
    <h1>Example</h1>
    <div>
      I just want to say <%= request.getAttribute("greeting") %>
    </div>Going to that servlet now executes business logic and then points to the JSP file for the view. You can forward from servlet to servlet too if needs be. The string you pass to forward() is whatever would be in the URI of the request so any <servlet-mapping> configurations in web.xml are used ;)
    There is some pretty in-depth documentation on the J2EE blueprints website, namely service-to-worker and front-controller patterns. I dare say if you're looking for this sort of code you'll want to look at the composite view pattern too (also on blueprints).

Maybe you are looking for

  • When i open pc an adobe bridge problem denotes purging

    when i open computer an adobe bridge problem denotes purging

  • Client hangs in App Store

    I have had this happen often.  I am managing a large number of Snow Leopard and Lion Servers.  On each machine, each user has their own Fusion 4 VM running.  Occaisonally when I log in (via ARD) to one of the VMs and access the "App Store", it hangs.

  • Multiple Edits in Photoshop not saving into Lightroom?

    In Lightroom 3 I was able to edit in Photoshop, save the file, then make another edit in photoshop and save it under a different name, and that file would also show up in Lightroom. For example; in Lightroom I select "Image 1" and select edit in phot

  • Run SunOne using normal user

    Hi, I have installed SunOne AppSvr7 on UNIX Server (SunOS) on my own directory "/export/home/SUNWappsvr7". I have installed the software using root permission. I can start and stop the app-server using root with no problem. However, I need to run/ope

  • Linking images in HorizontalList

    I am trying to create a Horizontal List of images which each link to a different webpage. I have simplified my code below. The Button in the Horizontal List works correctly when moved out of the HorizontalList, so I know the functions work. The icon,