JSP, Servlet, and Java Classes location in Tomcat

In tomcat, I want to know JSP files, Servlets, and Java classes
should put in different locations:
I put web.xml in the following:
C:\jakarta-tomcat-4.1.30\webapps\proj1\WEB-INF
I put all JSP files in the following:
C:\jakarta-tomcat-4.1.30\webapps\proj1
I put all servlet files in the following:
C:\jakarta-tomcat-4.1.30\webapps\proj1\WEB-INF\classes
I put all Java classes in the following with package proj1:
C:\jakarta-tomcat-4.1.30\webapps\proj1\WEB-INF\classes\proj1
When I execute JSP files, it has HTTP error 404, file not found.
The content of web.xml is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>proj1</display-name>
<description>
     proj1
</description>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Please advise. thanks!!!

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>Where's the servlet definition that maps to "invoker"?

Similar Messages

  • Deploying the JSPs, Servlets and Java class files

    Hello All,
    I'm very new to the Oracle 9i AS. We are using Version 1.0.2.2.
    How do we deploy the JSPs, Servlets, and Java class files (simple class files, not EJBs)?
    plese give us the procedure and stpes how to deply or the links for the same.
    Thanks,
    Santhosh.

    Hi
    I guess u r running apache-jserv as servlet engine for your jsp and servlets. If its so, jsp files can be run without any additonal configuration by putting the jsp file under document root or any subdirectory and for running servlets u have to add classpath entries for your servlet in jserv.properties file.
    To make sure that your servlet engine is working, try
    http://servername:port/servlet/IsItWorking, if u get success msg that means servlet engine is working fine.
    Hope this will help
    Regards
    Kumaran

  • Using a single connection for jsp, servlets and classes

    Hi! I'm building a web site that uses JSP, Servlets and some classes. I use database access in all my pages. I want to open a connection and use it for all the pages while the user is in my site, so I don't need to open a connection with every new jsp or servlet page. My software must be capable of connection with various databases, like SQLServer, Oracle, Informix, etc... so the solution must not be database (or OS or web server) dependant.
    Can you help me with this? Some ideas, links, tips? I'll REALLY appreciate your help.
    Regards,
    Raul Medina

    use an initialiation servlet with pooled connection which can be accessed as sesssion object.
    Abrar

  • How to set the classpath and path from the jsp to call  java class function

    Hi Exprets,
    I have a requirement to call a java class function which returns a hashmap object from the jsp. The java class in present in one jar file and that jar file is location somewhere in unix path. So the requirement is to set the classpath for that jar file and then create the object of the java class and then call the function.
    If any one know how to achieve it, please reply as soon as possible.
    thanks in advance,
    swapna soni.

    It is never advisable to store large data sets in the session. But it will depend on a lot of factors:
    1. How costly is the query retrieving the data from the database?
    If it's a complex query with lots of joins and stuff, then it will be better to store it in the session as processing the query each time will take a lot of time and will decrease performance. On the other hand if the query is simple then it's advisable not to store it in the session, and fetch it each time.
    2. Are there chances for the data to become stale within a session?
    In this case storing the data is session will mean holding the stale data till the user session lasts which is not right.
    3. How many data sets does the session already holds?
    If there are large no. of data sets already present in the session, then it's strictly not advisable to store the data in the session.
    4. Does the server employ some kind of caching mechanism?
    Using session cache can definitely improve performance.
    You will have to figure out, what is the best way analyzing all the factors and which would be best in the situation. As per my knowledge, session is the only place where session specific data can be stored.
    Also, another thing, if the data set retrieved is some kind of data to be displayed in reports, then it would be better to use a pagination query, which will retrieve only the specific no. of rows at a time. A navigation provided in the UI will retrieve the next/previous data set to display.
    Thanks,
    Shakti

  • How to convert a .jsp to a .java/.class file for use in peoplesoft

    Hi java/jsp experts,
    I want to convert a .jsp to a .java/.class file. is there a tool available, please let me know if you have any pointers....
    or can i do it manually:
    these are a few lines that the .jsp contains, and i would like to translate this to be in .java/.class format:
    <%@ page import="sun.misc.BASE64Encoder, javax.crypto., javax.crypto.spec."%>
    <%@ page import="java.util.StringTokenizer" %>
    <%@ page import="java.util.Map" %>
    <%!
    sb.append("<input type=\"hidden\" name=\"orderPage_serialNumber\" value=\"");
    sb.append(serialNumber);
    sb.append("\">\n");
    return sb.toString();
    %>
    how can i translate the above import statements and html elements from jsp to java, please let me know.
    Once i have the .java file created from the .jsp, I will compile .java to create the .class file and invoke the .class in peoplecode by using java apis available in peopletools.
    Thanks in advance.

    Is there a way convert a binary .exe file( compiled by
    another compiler) into Java .class/.jar file ? Anyone
    know of a free program that can do this?It's not possible. There are many decompilers and disassemblers for Java but nothing will take you from ANY binary to Java source. It would be the end of computing as we know it and the beginning of a new era -:)

  • Examination system using JSP/SErvlet and MySQL

    Hi
    I am new to JSP /servlet.
    I am designing online examination system using JSP/Servlet and MySQL ,where multiple choice questions would be selected randomly from the database. After completion of the examination user gets the results ,also the results would be stored in the database for the future reference.
    Can anyone guide me for this? If possible give me the code for similar type of application.
    Thanks

    Sounds like you want someone else to do your homework for you, did you not read this:
    "This forum works so much better when you try to program the code yourself, then let us know where it doesn't work. Otherwise you learn very little, and we work a whole lot."
    and this
    "If you want free code, have you tried searching Google for it? You may want to consider looking for survey software. It will give you the question/answer capabilities then all you have to do is find a way to grade the survey (if you will)...
    If you are using Tomcat as your server, which you probably are, there is a jdbc tutorial included in the documentation, that is the fastest way to set up your database.
    As for your random selection, have a look at Math.random(), this is one way to generate random numbers, you will need an algorithm to convert this value (between 0.0 and 1.0) into a form that can be used to select information from your database.

  • Calling a servlet in java class

    Hello,
    I try to call a servlet from java class
    but is dose not work
    what should be the problem
       public void callServlet()
              try
                            // xxservlet is the servlet name
                   URL url = new URL("http://www.mydomain.com/xxservlet");
                   URLConnection hpCon = url.openConnection();
                   hpCon.setDoOutput(true);
                   OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
                   out.write("This Is a Test");
                   out.flush();
                   out.close();
              }catch(Exception ex){ex.printStackTrace();}     
    // My Servlet  is in package servlets
    public class XXServlet extends HttpServlet
        public void service(HttpServletRequest req, HttpServletResponse resp) {
            try {
                 ServletInputStream sin = req.getInputStream();
                 int len = req.getContentLength();
                    byte[] input = new byte[len];
                    ServletInputStream sin = req.getInputStream();
                   int c, count = 0 ;
                   while ((c = sin.read(input, count, input.length-count)) != -1) {
                       count +=c;
                  sin.close();
                  String inString = new String(input);
                  System.out.println("Servlet is running ...."+inString);
            } catch (IOException e) {
                try{
                    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    resp.getWriter().print(e.getMessage());
                    resp.getWriter().close();
                } catch (IOException ioe) {
    // web.xml
    <servlet>
           <servlet-name>xxservlet</servlet-name>
           <servlet-class>servlets.XXServlet</servlet-class>
        </servlet>
       <servlet-mapping>
        <servlet-name>xxservlet</servlet-name>
        <url-pattern>/xxservlet</url-pattern>
      </servlet-mapping>
    }regards
    Edited by: the_Orient on Mar 30, 2009 3:16 AM

    I have start servlet from brwoser only to test that servlet works fine
    A gain what I need
    I want to call a servlet from a javs class
    URL url = new URL("http://www.mydomain.com/myservlet");
      URLConnection hpCon = url.openConnection();
      hpCon.setDoOutput(true);
      OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
      out.write("Hello Woprld");
      out.flush();
      out.close();// Servlet
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
            try {
                  String xp =req.getSession().getServletContext().getRealPath("/");
                  File f = new File(xp+"/students/info.txt");
                  f.createNewFile();
            } catch (IOException e) {
                try{
                    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    resp.getWriter().print(e.getMessage());
                    resp.getWriter().close();
                } catch (IOException ioe) {
    problem file can not be created
        public void doPost(HttpServletRequest req, HttpServletResponse resp)
    }I hope that is clear

  • Calling Servlet from Java Class in eclipse

    Hi ,
    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();
    I am using the above code in JAVA to Connect to Servlet I have given Print statement in Servlet such that whenever it calls it prints on Console but when I try to run the code the Statement is not printed in the Console of eclipse I think URL connection is not able to establish any connection ..... if any has solution for this please reply
    Thanks & Regards,
    Arvind

    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();Why should the Servlet running in different Runtime print on your Eclipse Runtime. Please be more clear about the question.

  • (261680070) Q SYNCH-11 How do my web service methods accees EJBs and java classes?

    A<SYNCH-11> How do my web service methods accees EJBs and java classes?
    A<SYNCH-11> It is simple to use java classes, just do it as you would ordinarily.
    The .jws file really contains a simple class so you can program with it in the same
    way that you would use a regular Java class.
    To use an EJB you can go and access it directly as you would with any EJB remote
    client (lookup home stub, create, etc) or if the EJB is deployed to WLS you can use
    a control to provide a very simple wrapper to the EJB. We will see this in detail
    on Thursday in the ADVC module.

    Futher information about the possibility of callback:
    It may be possible for a synchronous only web service (i.e. MS .net) to even paticipant
    in the callback functionality of asynchronous web services. If the client implements
    the appropriate methods for the callback but listens for them on a different port
    or binding than the SOAP request, then web service may be able to build a response
    if the client's "callback URL" is submitted as the beginning part of a conversation.
    Watch the BEA developer forum (http://dev2dev.bea.com) for more information about
    this approach and other tips and techniques for building web services.
    "Adam FitzGerald" <[email protected]> wrote:
    >
    Q<SYNCH-03> I heard that MS .net only implements synchrnonus method? If
    this is true.
    Does it means my async methods will only work with J2EE clients?
    A<SYNCH-03> I do not know the limitations of .net but let me point out that
    is very
    difficult to provide asynchronous web service method invocation (this is
    different
    from an asynchronous web service). HTTP as a general communication protocol
    is based
    on a request and response paradigm so your client libraries will mostly
    likely be
    expecting a response even if it is empty (check the asynchronous example
    from today
    to see that the start method still returns an empty response). You must
    distinguish
    this from the notion of an asynchronous web service which is a business
    operation
    that occurs on the server whose return value/result is not directly associated
    with
    building response to the client. An asynchronous web service can (and generally
    will)
    be started and stopped with web service operations that are invoked synchronously.
    Thus MS .net clients can still be client to WLS hosted web services.

  • Question about main difference between Java bean and Java class in JSP

    Hi All,
    I am new to Java Bean and wonder what is the main difference to use a Bean or an Object in the jsp. I have search on the forum and find some post also asking the question but still answer my doubt. Indeed, what is the real advantage of using bean in jsp.
    Let me give an example to illustrate my question:
    <code>
    <%@ page errorPage="errorpage.jsp" %>
    <%@ page import="ShoppingCart" %>
    <!-- Instantiate the Counter bean with an id of "counter" -->
    <jsp:useBean id="cart" scope="session" class="ShoppingCart" />
    <html>
    <head><title>Shopping Cart</title></head>
    <body bgcolor="#FFFFFF">
    Your cart's ID is: <%=cart.getId()%>.
    </body>
    <html>
    </code>
    In the above code, I can also create a object of ShoppingCart by new operator then get the id at the following way.
    <code>
    <%
    ShoppingCart cart = new ShoppingCart();
    out.println(cart.getId());
    %>
    </code>
    Now my question is what is the difference between the two method? As in my mind, a normal class can also have it setter and getter methods for its properties. But someone may say that, there is a scope="session", which can be declared in an normal object. It may be a point but it can be easily solved but putting the object in session by "session.setAttribute("cart", cart)".
    I have been searching on this issue on the internet for a long time and most of them just say someting like "persistance of state", "bean follow some conventions of naming", "bean must implement ser" and so on. All of above can be solved by other means, for example, a normal class can also follow the convention. I am really get confused with it, and really want to know what is the main point(s) of using the java bean.
    Any help will be highly apprecaited. Thanks!!!
    Best Regards,
    Alex

    Hi All,
    I am new to Java Bean and wonder what is the main
    difference to use a Bean or an Object in the jsp. The first thing to realize is that JavaBeans are just Plain Old Java Objects (POJOs) that follow a specific set of semantics (get/set methods, etc...). So what is the difference between a Bean and an Object? Nothing.
    <jsp:useBean id="cart" scope="session" class="ShoppingCart" />
    In the above code, I can also create a object of
    ShoppingCart by new operator then get the id at the
    following way.
    ShoppingCart cart = new ShoppingCart();
    out.println(cart.getId());
    ...Sure you could. And if the Cart was in a package (it has to be) you also need to put an import statement in. Oh, and to make sure the object is accessable in the same scope, you have to put it into the PageContext scope. And to totally equal, you first check to see if that object already exists in scope. So to get the equivalant of this:
    <jsp:useBean id="cart" class="my.pack.ShoppingCart"/>Then your scriptlet looks like this:
    <%@ page import="my.pack.ShoppingCart %>
    <%
      ShoppingCart cart = pageContext.getAttribute("cart");
      if (cart == null) {
        cart = new ShoppingCart();
        pageContext.setAttribute("cart", cart);
    %>So it is a lot more work.
    As in my mind, a normal class can also
    have it setter and getter methods for its properties.True ... See below.
    But someone may say that, there is a scope="session",
    which can be declared in an normal object.As long as the object is serializeable, yes.
    It may be
    a point but it can be easily solved but putting the
    object in session by "session.setAttribute("cart",
    cart)".Possible, but if the object isn't serializable it can be unsafe. As the point I mentioned above, the useBean tag allows you to check if the bean exists already, and use that, or make a new one if it does not yet exist in one line. A lot easier than the code you need to use otherwise.
    I have been searching on this issue on the internet
    for a long time and most of them just say someting
    like "persistance of state", "bean follow some
    conventions of naming", "bean must implement ser" and
    so on. Right, that would go along the lines of the definition of what a JavaBean is.
    All of above can be solved by other means, for
    example, a normal class can also follow the
    convention. And if it does - then it is a JavaBean! A JavaBean is any Object whose class definition would include all of the following:
    1) A public, no-argument constructor
    2) Implements Serializeable
    3) Properties are revealed through public mutator methods (void return type, start with 'set' have a single Object parameter list) and public accessor methods (Object return type, void parameter list, begin with 'get').
    4) Contain any necessary event handling methods. Depending on the purpose of the bean, you may include event handlers for when the properties change.
    I am really get confused with it, and
    really want to know what is the main point(s) of
    using the java bean.JavaBeans are normal objects that follow these conventions. Because they do, then you can access them through simplified means. For example, One way of having an object in session that contains data I want to print our might be:
    <%@ page import="my.pack.ShoppingCart %>
    <%
      ShoppingCart cart = session.getAttribute("cart");
      if (cart == null) {
        cart = new ShoppingCart();
        session.setAttribute("cart", cart);
    %>Then later where I want to print a total:
    <% out.print(cart.getTotal() %>Or, if the cart is a JavaBean I could do this:
    <jsp:useBean id="cart" class="my.pack.ShoppingCart" scope="session"/>
    Then later on:
    <jsp:getProperty name="cart" property="total"/>
    Or perhaps I want to set some properties on the object that I get off of the URL's parameter group. I could do this:
    <%
      ShoppingCart cart = session.getAttribute("cart");
      if (cart == null) {
        cart = new ShoppingCart();
        cart.setCreditCard(request.getParameter("creditCard"));
        cart.setFirstName(request.getParameter("firstName"));
        cart.setLastName(request.getParameter("lastName"));
        cart.setBillingAddress1(request.getParameter("billingAddress1"));
        cart.setBillingAddress2(request.getParameter("billingAddress2"));
        cart.setZipCode(request.getParameter("zipCode"));
        cart.setRegion(request.getParameter("region"));
        cart.setCountry(request.getParameter("country"));
        pageContext.setAttribute("cart", cart);
        session.setAttribute("cart", cart);
      }Or you could use:
    <jsp:useBean id="cart" class="my.pack.ShoppingCart" scope="session">
      <jsp:setProperty name="cart" property="*"/>
    </jsp:useBean>The second seems easier to me.
    It also allows you to use your objects in more varied cases - for example, JSTL (the standard tag libraries) and EL (expression language) only work with JavaBeans (objects that follow the JavaBeans conventions) because they expect objects to have the no-arg constuctor, and properties accessed/changed via getXXX and setXXX methods.
    >
    Any help will be highly apprecaited. Thanks!!!
    Best Regards,
    Alex

  • JSP, Servlet and RMI

    HI,
    I have developed a simple interface to start and stop a java application.
    In practice I have a command panel (a JSP page) that communicates with a servlet that through RMI is able to start and stop my external java application.
    JSP and servlet are under Tomcat.
    Here are my codes:
    JSP:
    <%@ page language="java" session="true" autoFlush="true" isThreadSafe="true"
    contentType="text/html; charset=ISO-8859-1" isErrorPage="false" %>
    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body>
    <form action="controlpanel" method="get" name="pannello" id="pannello">
    <p>
    <select name="op" size="1" id="op">
    <option value="start" selected>start</option>
    <option value="stop">stop</option>
    </select>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    </body>
    </html>
    SERVLET:
    * Created on 03-Dec-2003
    * To change the template for this generated file go to
    * Window - Preferences - Java - Code Generation - Code and Comments
    package servlet;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.rmi.Naming;
    import java.rmi.RMISecurityManager;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import server.Mmce;
    * @author root
    * To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Generation - Code and Comments
    public class CommandPanel extends HttpServlet
         protected void doGet(HttpServletRequest request,
                   HttpServletResponse response) throws ServletException, IOException
              String operation = request.getParameter("op");
              log("OPERAZIONE="+operation);
              PrintWriter out = response.getWriter();
              if (System.getSecurityManager() == null)
                   System.setSecurityManager(new RMISecurityManager());
              try
                   Mmce comp=(Mmce)Naming.lookup("rmi://192.168.1.113/Mmce");               
                   if (operation.equalsIgnoreCase("start"))
                        comp.start();
                   else
                        comp.stop();
              catch (Exception e)
                   log(e.getMessage());
                   StackTraceElement[] el = e.getStackTrace();
                   String errore = "";
                   for (int g = 0; g < el.length; g++)
                        errore += el[g].toString()+"\n";
                   log(errore);               
              finally
                   response.setContentType("text/html");
                   log("Write html");
                   RequestDispatcher rd = request.getRequestDispatcher("/panel.jsp");
                   rd.forward(request,response);
    // Follow part is commented
    /**out.println("<html>");
                   out.println("<head>");
                   out.println("<title>Pannello di comando</title>");
                   out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
                   out.println("</head>");
                   out.println("<body>");
                   out.println("<form action=\"controlpanel\" method=\"get\" name=\"pannello\" id=\"pannello\">");
                   out.println("<p>");
                   out.println("<select name=\"op\" size=\"1\" id=\"op\">");
                   out.println("<option value=\"start\" selected>start</option>");
                   out.println("<option value=\"stop\">stop</option>");
                   out.println(" </select>");
                   out.println("</p>\n<p>");
                   out.println("<input type=\"submit\" name=\"Submit\" value=\"Submit\">\n</p>");     
                   out.println("</form>\n</body>\n</html>");
    All works fine for two times in that I start and stop application. At the third time, when i start my application from jsp, I receive this Tomcat error:
    type Status report
    message /panel.jsp
    description The requested resource (/panel.jsp) is not available.
    like the jsp could not be reachble.
    If I try to stop and restart the application from Tomcat Manager panel and go to the url of JSP, I have this exception:
    org.apache.jasper.JasperException: Unable to compile class for JSP
         org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:587)
         org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:324)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:284)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:499)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:200)
    root cause
    java.lang.NullPointerException
         sun.misc.URLClassPath$3.run(URLClassPath.java:311)
         java.security.AccessController.doPrivileged(Native Method)
         sun.misc.URLClassPath.getLoader(URLClassPath.java:308)
         sun.misc.URLClassPath.getLoader(URLClassPath.java:285)
         sun.misc.URLClassPath.getResource(URLClassPath.java:155)
         java.net.URLClassLoader$1.run(URLClassLoader.java:190)
         java.security.AccessController.doPrivileged(Native Method)
         java.net.URLClassLoader.findClass(URLClassLoader.java:186)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:192)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:110)
         org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:582)
         org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:324)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:284)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:499)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:200)
    note The full stack trace of the root cause is available in the Tomcat logs.
    I need to restart Tomcat and then I have the same proble and then that my JSP works fine for two times and at the third time come unreachble.
    If I change the servlet's part in which I do the forward to the JSP and put the commented part, the application works fine.
    Anybody can tell me why my JSP come unreachble?
    Thanks
    Emanuele Pecorari

    I add this thing:
    if I add in java.policy this permission:
    permission java.security.AllPermission;
    all works fine.
    I want to know what exactly permission I must put in my file in order that the application works fine in the same handle.

  • User parameter are not show in database using Servlet and java Bean

    Hello Sir,
    when I insert the parameter in run time, weblogic server and JSP show that parameter are saved.
    Allthough row increment in database but they not show in database.
    Here My Code:
    login.html:
    <html>
    <head>
    <title>A simple JSP application</title>
    <head>
    <body>
    <form method="get" action="tmp" >
    Name: <input type="text" name="user">
    Password: <input type="password" name="pass">
    <input type="Submit" value="Submit">
    </form>
    </body>
    </html>LoginServlet.java:import javax.servlet.*;
    import javax.servlet.http.*;
    public class LoginServlet extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{
    try
    String user=request.getParameter("user");
    String pass=request.getParameter("pass");
    co.SimpleBean st = new co.SimpleBean();
    st.setuserName(user);
    st.setpassword(pass);
    request.setAttribute("user",st);
    request.setAttribute("pass",st);
    RequestDispatcher dispatcher1 =request.getRequestDispatcher("submit.jsp");
    dispatcher1.forward(request,response);
    catch(Exception e)
    e.printStackTrace();
    }SimpleBean.java:
    package co;
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.util.*;
    public class SimpleBean {
    private String user="";
    private String pass="";
    private String s="";
    public String getuserName() {
    return user;
    public void setuserName(String user) {
    this.user = user;
    public String getpassword() {
    return pass;
    public void setpassword(String Pass) {
    this.pass= pass ;
    public String issueData()
    try
    System.out.println("Printed*************************************************************");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("Connection loaded");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@VijayKumar-PC:1521:XE","SYSTEM","SYSTEM");
    System.out.println("Connection created");
    PreparedStatement st=con.prepareStatement("insert into vij2 values(?,?)");
    System.out.println("~~~~~~~~~~~~~~~~~~~~");
    String NAME=getuserName();
    st.setString(1,NAME);
    String PASSWORD=getpassword();
    st.setString(2,PASSWORD);
      st.executeUpdate();
    System.out.println("Query Executed");
    con.close();
    s=  "Your logging is saved in DB ";
    System.out.println("Your logging is saved in DB *****************");
    return(s);
    catch(Exception e)
    e.printStackTrace();
    return "failed";
    }submit.jsp:This is Submit page
    <jsp:useBean id="st" class="co.SimpleBean"/>
    <jsp:setProperty name="st" property="*" />
    <jsp:getProperty name="st" property="userName" /> <br>
    <jsp:getProperty name="st" property="password" /> <br>
    <% st.issueData();%>
    <%
    out.println("Ur data is saved in DB");
    %>Please Help me.
    Thanks.

    Ok, this seems to be a long and convoluted path to do absolutely nothing.
    You submit the form.
    You run a servlet that gets the parameters correctly (good), creates a SimpleBean (good) and then sets this into request attribute space under the names "user" and "pass" - (why?)
    You then forward to the jsp: submit.jsp.
    Submit.jsp creates a new SimpleBean, and attempts to populate it with <jsp:setProperty>. You then call the issueData method on it.
    Your complaint: Rows are being created in the database which have empty string values instead of the parameters you have passed.
    So, why are the values blank? Where do you think these values should be coming from?
    Looking at SimpleBean we find one mistake - you have mis-named your get/set methods.
    To properly follow java beans standards, you should use camel-case for your methods.
    Rather than getuserName() the method should be getUserName(). getpassword() should be getPassword() etc etc.
    The method getUserName() defines a property "userName" for the bean.
    Once that is fixed, lets go to submit.jsp. The <jsp:setProperty> statement will try and set all properties of the bean from the request parameters.
    There are no request parameters "userName" or "password" so those values don't get set in the bean, therefore it uses their default value of empty string - "".
    There ARE request parameters called "user" and "pass" but because they aren't properties of the bean, they get ignored.
    As a result, the values are empty string, and that is exactly what gets inserted into the database.
    Ways to fix this
    1 - rename your parameters on your form to be "userName" and "password" to match the bean. That way the <jsp:setProperty> tag will populate them properly.
    or
    2 - Call issueData() method from your servlet after you have created the SimpleBean. Better in my opinion as you then don't have any scriptlet code on a JSP page.
    Cheers,
    evnafets

  • Call a function in servlet from java class.

    Hi,
    I am implementing a client/server technology by trying to convert a java desktop client into Browser based. As part of user authetication the only way I know that a username /password does not match is from the servers message as i dont have documentation of the backend servers database.
    Here is a fucntion which receives lines form server.
    public class ServerComm{
    public synchronized void receiveMessage(String  serverMessage){
    if (serverMessage.equals("Login-Fail"))// Login-Fail is message from server if login fails
    LoginHandler.loginFail()//Login Handler is a servlet
    return
    }The Login Handler servlet is as follows.
    public class LoginHandler extends HttpServlet {
        /** Initializes the servlet.
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        /** Destroys the servlet.
        public void destroy() {
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected synchronized void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //some expressions.       
       //this is reached if login fails.
        public static void  loginFail(){
            HttpServletResponse response;
        //redirected to wronglogin web page.  
      response.sendRedirect("/mCVW/wronglogin.jsp");
        /** Handles the HTTP <code>GET</code> method.
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Handles the HTTP <code>POST</code> method.
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
       }Now there is problem in loginFail() method in LoginHandler servlet does not work with the type of response decleration . I need some assistance from any one to make this work or propose a better solution for determining the user authetication with the restriction i have.
    Thank you.

    hmm...I haven't tried this before...but does this work by any chance?
    In your ServerComm class, create new HttpServletRequest and Response objects and get a RequestDispatcher object from request.
    Eg : if (serverMessage.equals("login-fail"){
    HttpServletRequest request = new HttpServletRequest ();
    HttpServletResponse response = new HttpServletResponse ();
    request.setAttribute("function_id", "loginFail");
    RequestDispatcher dispatcher = request.getRequestDispatcher("http://servername:port/ServletName");
    //give the complete path of your servlet
    dispatcher.forward(request, response);
    and in your Servlet, get this function_id and if its loginFail, redirect it to wronlogin.jsp...
    public class MyServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    String function_id = request.getAttribute("function_id");
    if(function_id.equalsIgnoreCase("loginFail"))
    //forward to ur jsp
    getServletConfig().getServletContext().getRequestDispatcher(wronlogin.jsp").forward(request, response);
    }

  • JSP Servlet and convert the result set of an SQL Query To XML file

    Hi all
    I have a problem to export my SQL query is resulty into an XML file I had fixed my servlet and JSP so that i can display all the records into my database and that the goal .Now I want to get the result set into JSP so that i can create an XML file from that result set from the jsp code.
    thisis my servlet which will call the jsp page and the jsp just behind it.
    //this is the servlet
    import java.io.*;
    import java.lang.reflect.Array;
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import javax.sql.*;
    public *class *Campaign *extends *HttpServlet
    *private* *final* *static* Logger +log+ = Logger.+getLogger+(Campaign.*class*.getName());
    *private* *final* *static* String +DATASOURCE_NAME+ = "jdbc/SampleDB";
    *private* DataSource _dataSource;
    *public* *void* setDataSource(DataSource dataSource)
    _dataSource = dataSource;
    *public* DataSource getDataSource()
    *return* _dataSource;
    *public* *void* init()
    *throws* ServletException
    *if* (_dataSource == *null*) {
    *try* {
    Context env = (Context) *new* InitialContext().lookup("java:comp/env");
    _dataSource = (DataSource) env.lookup(+DATASOURCE_NAME+);
    *if* (_dataSource == *null*)
    *throw* *new* ServletException("`" + +DATASOURCE_NAME+ + "' is an unknown DataSource");
    } *catch* (NamingException e) {
    *throw* *new* ServletException(e);
    protected *void *doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    Connection conn = *null*;
    *try* {
    conn = getDataSource().getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select post_id,comments,postname from app.posts");
    // out.println("Le r&eacute;sultat :<br>");
    ArrayList <String> Lescomments= *new* ArrayList<String>();
    ArrayList <String> Lesidentifiant = *new* ArrayList<String>();
    ArrayList <String> Lesnoms = *new* ArrayList <String>();
    *while* (rs.next()) {
    Lescomments.add(rs.getString("comments"));
    request.setAttribute("comments",Lescomments);
    Lesidentifiant.add(rs.getString("post_id"));
    request.setAttribute("id",Lesidentifiant);
    Lesnoms.add(rs.getString("postname"));
    request.setAttribute("nom",Lesnoms);
    rs.close();
    stmt.close();
    *catch* (SQLException e) {
    *finally* {
    *try* {
    *if* (conn != *null*)
    conn.close();
    *catch* (SQLException e) {
    // les param&egrave;tres sont corrects - on envoie la page r&eacute;ponse
    getServletContext().getRequestDispatcher("/Campaign.jsp").forward(request,response);
    }///end of servlet
    }///this is the jsp page called
    <%@ page import="java.util.ArrayList" %>
    <%
    // on r&eacute;cup&egrave;re les donn&eacute;es
    ArrayList nom=(ArrayList)request.getAttribute("nom");
    ArrayList id=(ArrayList)request.getAttribute("id");
    ArrayList comments=(ArrayList) request.getAttribute("comments");
    %>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    Liste des campagnes here i will create the xml file the problem is to display all rows
    <hr>
    <table>
    <tr>
    </tr>
    <tr>
    <td>Comment</td>
    <td>
    <%
    for( int i=0;i<comments.size();i++){
    out.print("<li>" + (String) comments.get(i) + "</li>\n");
    }//for
    %>
    </tr>
    <tr>
    <td>nom</td>
    <td>
    <%
    for( int i=0;i<nom.size();i++){
    out.print("<li>" + (String) nom.get(i) + "</li>\n");
    }//for
    %>
    </tr>
    <tr>
    <td>id</td>
    <td>
    <%
    for( int i=0;i<id.size();i++){
    out.print("<li>" + (String) id.get(i) + "</li>\n");
    }//for
    %>
    </tr>
    </table>
    </body>
    </html>
    This is how i used to create an XML file in a JSP page only without JSP/SERVLET concept:
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%
    // Identify a carriage return character for each output line
    int iLf = 10;
    char cLf = (*char*)iLf;
    // Create a new empty binary file, which will content XML output
    File outputFile = *new* File("C:\\Users\\user\\workspace1\\demo\\WebContent\\YourFileName.xml");
    //outputFile.createNewFile();
    FileWriter outfile = *new* FileWriter(outputFile);
    // the header for XML file
    outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);
    try {
    // Define connection string and make a connection to database
    Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/SAMPLE","app","app");
    Statement stat = conn.createStatement();
    // Create a recordset
    ResultSet rset = stat.executeQuery("Select * From posts");
    // Expecting at least one record
    *if*( !rset.next() ) {
    *throw* *new* IllegalArgumentException("No data found for the posts table");
    outfile.write("<Table>"+cLf);
    // Parse our recordset
    // Parse our recordset
    *while*(rset.next()) {
    outfile.write("<posts>"+cLf);
    outfile.write("<postname>" + rset.getString("postname") +"</postname>"+cLf);
    outfile.write("<comments>" + rset.getString("comments") +"</comments>"+cLf);
    outfile.write("</posts>"+cLf);
    outfile.write("</Table>"+cLf);
    // Everything must be closed
    rset.close();
    stat.close();
    conn.close();
    outfile.close();
    catch( Exception er ) {
    %>

    Please state your problem that you are having more clearly so we can help.
    I looked at your code I here are a few things you might consider:
    It looks like you are putting freely typed-in comments from end-users into an xml document.
    The problem with this is that the user may enter characters in his text that have special meaning
    to xml and will have to be escaped correctly. Some of these characters are less than character, greater than character and ampersand character.
    You may also have a similiar problem displaying them on your JSP page since there may be special characters that JSP has.
    You will have to read up on how to deal with these special characters (I dont remember what the rules are). I seem to recall
    if you use CDATA in your xml, you dont have to deal with those characters (I may be wrong).
    When you finish writing your code, test it by entering all keyboard characters to make sure they are processed, stored in the database,
    and re-displayed correctly.
    Also, it looks like you are putting business logic in your JSP page (creating an xml file).
    The JSP page is for displaying data ONLY and submitting back to a servlet. Put all your business logic in the servlet. Putting business logic in JSP is considered bad coding and will cause you many hours of headache trying to debug it. Also note: java scriptlets in a JSP page are only run when the JSP page is compiled into a servlet by java. It does not run after its compiled and therefore you cant call java functions after the JSP page is displayed to the client.

  • Calling Servlet from Java-Class

    Hi,
    I have a normal java-class that is working with request/response Objects. From within this class I want to call a local servlet, let it do some work with the request and the response and then return it to the class.
    I guess the RequestDispatcher can only be called from within a Servlet, but my class is not a servlet.
    The getServlet()-method is not working any more.
    Maybe somebody has an idea.
    Thanks a lot,
    Matthias

    Hi,
    I have a normal java-class that is working with
    request/response Objects. From within this class I
    want to call a local servlet, let it do some work with
    the request and the response and then return it to the
    class.
    I guess the RequestDispatcher can only be called from
    within a Servlet, but my class is not a servlet.
    The getServlet()-method is not working any more.
    Maybe somebody has an idea.
    Thanks a lot,
    MatthiasThis is not very pretty, so I think you should redessign, but you can open a URLConnection from your class pointing to the URL of the servlet. As far as I know you can't invoke a servlet directly, because you can't get a reference to it, it can only be invoked by the container...

Maybe you are looking for

  • Text message sound going off randomly

    The sound of an incoming text message is constantly going off on my phone. I am not receiving new messages. I checked and it does not appear to be my other apps. Any ideas?

  • Why won't my iphone charge anymore?

    my iphone will not charge after the battery is bout half full..... and now it is not charging at all. I'm confused, can anyone help?

  • Can't see printer or shares when connected via Internet Sharing

    I recently switched from a 2006 to a 2008 Mac Pro. Rather than do a migration I simply took the hard drives from the old machine and put them in the new one. I then upgraded to Mountain Lion. I use Internet Sharing to share my Mac Pro's Ethernet conn

  • MSI GT70 - which ones are required drivers and apps? Which ones are optional?

    I have MSI GT70 0ND but I suppose lots of things will overlap with other GT70 even GT60 owners (Windows 8 x64). So which onces are needed and what are they? I will post some that I know, then ask you about the rest: http://www.msi.com/product/nb/GT70

  • Newbie needs urgent help

    Hi guys, I need to create a function that returns as string, the path or location of the file it is in. for example: this function will be in a file called A.java A.java has the path C/MyDocuments/Jenna/java/A.java so when I run this function, it ret