Servlet, how to use it?

I compile a servlet class:
public class HelloWorld extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          out.println("<HTML>");
          out.println("<HEAD>");
          out.println("<TITLE>Hello World!!</TITLE>");
          out.println("</HEAD>");
          out.println("<BODY>");
          out.println("</BODY>");
          out.println("</HTML>");
=====================================================
and generate a HelloWorld.class
but how to use the class? must it be used in a jsp file?
thx

if you want to hit the ground running with servlets, im me webactivex on yahoo messager, or e-mail [email protected].. http://sourceforge.net/projects/ambient/ is a webapplication engine that will let you build webapplications and do less coding!
im me I will tell u all you need to know.. matt

Similar Messages

  • How to use an IFrame with my servlet?

    Hello, my question is this (basically, I'm building a "social" application for one of the social networks out there,
    but I'm using a java servlet as my back-end server, though I don't know if it matters to my question) -
    I want to insert an iframe to my application, but I didn't find good material on how to use this, and what to add to my servlet
    for completing the communication with the iframe - can anyone give an example maybe, or a link to a good piece of code.
    Basically, what I want for my application is to simply allow a user to record a voice message, and save it somewhere,
    and for that I need to use a java library, and this is why I thought building it with an iframe that will directly communicate with my java servlet. - IS THIS A GOOD IDEA?
    thanks :)
    Kogan.

    IFrame is just a HTML element. You normally embed HTML elements in a JSP file. How to use an IFrame is covered by every average HTML tutorial.
    What's your actual problem?

  • How to use session variable in JSP function  & How to use both JSP  Servlet

    Hi,
    I am new to JSP and servlets
    Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
    I try to keep the hard coding part out of JSP.
    I dont how to use both JSP and Servlets in combination.
    Hence If needed I write some functions in JSP.
    but it gives me error
    +<%! public void abc()+
    +{+
    int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
    +}+
    +%>+
    Saying cannot find symbol session
    1) So can u please tell how can I access session variables within JSP function
    2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
    Thanks
    Venkat

    The application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...

  • How to use RMI objects in a servlet

    Hi,
    I have just run the example RMI program in the java tutorial in my linux pc. Also I have another method to just echo a string back. It works fine when calling from command line.
    Now I want to write a servlet that get a string when POSTed and call the RMI objects echo method and display the returned string.
    I use Tomcat-5.0 which is installed in /usr/local. I moved the remote object interface jar to the common/lib folder and import the interface in my Servlet. I use the following statements inside the servlet to get the RMI object reference.
                Registry registry = LocateRegistry.getRegistry("localhost");
                Rser comp = (Rser) registry.lookup("rmiser");When i use this in my servlet the tomcat stops working.
    Also I don't know how to specify the code base and security policy which I use in command prompt when calling RMI object.
    Pls suggest me what to do and also specify any resources that explain this task step by step.
    Thanks.

    restarted the system and caught the following exception while calling the servlet.
    Apr 30, 2009 12:24:15 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 3861 ms
    java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
         at java.security.AccessController.checkPermission(AccessController.java:546)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
         at java.net.Socket.connect(Socket.java:513)
         at java.net.Socket.connect(Socket.java:469)
         at java.net.Socket.<init>(Socket.java:366)
         at java.net.Socket.<init>(Socket.java:180)
         at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
         at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
         at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
         at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
         at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
         at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
         at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
         at RequestParamExample1.doGet(RequestParamExample1.java:94)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at filters.ExampleFilter.doFilter(ExampleFilter.java:101)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
         at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
         at java.lang.Thread.run(Thread.java:619)
    Apr 30, 2009 12:25:19 PM org.apache.coyote.tomcat5.CoyoteAdapter service
    SEVERE: An exception or error occurred in the container during the request processing
    java.security.AccessControlException: access denied (java.lang.RuntimePermission setContextClassLoader)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
         at java.security.AccessController.checkPermission(AccessController.java:546)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         at java.lang.Thread.setContextClassLoader(Thread.java:1351)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
         at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
         at java.lang.Thread.run(Thread.java:619)
    Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.security.AccessControlException: access denied (java.lang.RuntimePermission setContextClassLoader)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
         at java.security.AccessController.checkPermission(AccessController.java:546)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         at java.lang.Thread.setContextClassLoader(Thread.java:1351)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1623)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1608)
         at java.lang.Thread.run(Thread.java:619)
    Hope u can find it now.
    the line
    at RequestParamExample1.doGet(RequestParamExample1.java:94)
    is the file I am editing and using to call RMI.
    Edited by: itsraja on Apr 30, 2009 12:06 AM

  • How to create the servlet as acontroller  and how to use it

    how to create the servlet as acontroller and how to use it

    >
    John
    Please update your forum profile with a real handle instead of "914824".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I am going to have over 50 buttons in a page, Why? This would be a most unusual UI paradigm. I've never seen such a page, which suggests that whatever you want to do is normally done another way. Please explain the requirement in more detail.
    just wanted to know if its possible to do something like this in java.
    Java is not used in programming APEX UI behaviour. Java and JavaScript may share initial syllables, but they are not closely related.
    It's possible to achieve a great deal in JavaScript, but a clear definition of the requirements is necessary. Do you mean the buttons should be dynamically generated? If so, yes, this is possible in JavaScript. What would drive the process?
    Also, i would like to have dynamic action on it, for example, when the button is pressed, fill a string of text into other items(text field) within the page. Without more detail its not possible to make any specific suggestions. For example, I certainly would not want to create 50+ individual dynamic actions relating to different buttons.

  • How to use multithreads in servlet or beans?

    I need a servlet to run every 2 minutes to refresh a application varible.How can I do this?Please show me code examples,Thanks!!

    sounds to me the application should make periodic requests to the servlet, if so, use a thread in the app to request/sleep.

  • How to use resource servlet ?

    Hi all,
    Does any body know know how to use resource servlet to share resources (xsd, wsdl etc) in OSB ? Kindly provid eme witht the steps
    Thank you.

    Hi Eric,
    We can share the resource in the following way, but unfortunately OEPE doesnt accept http urls in schemaLocation arrtibute
    How can I get the WSDL/Policy/MFL/Schema/Proxy via HTTP?
    You can retrieve many of the resource types directly from the OSB server by using HTTP instead
    of needing to use the service bus console. The general pattern for the URL is as follows:
    http://[hostname]:[port]/sbresource?[Resource Type]/[Project Name]/[Resource Name]
    CHAPTER 18 ■ HOW DO I . . . ? 477
    The [Resource Type] section of the URL may be any one of the following values:
    • BIZ
    • MFL
    • POLICY
    • PROXY
    • SCHEMA
    • WSDL
    The URL must be UTF-8 encoded. If the resource is stored in a directory, then the directory
    structure needs to be declared explicitly in the URL also.
    For example, in the Hello World project in Chapter 4 of this book, we defined aWSDL resource
    in the WSDL folder of the project. The name of that WSDL resource is set to HelloWorld. To retrieve
    this WSDL, you would use the following URL:
    http://localhost:7001/sbresource?WSDL/Hello+World/WSDL/HelloWorld

  • How can i upload files in servlets and also using jsp

    means that uploading files(.doc) or any files by using servlets and jsps

    yawmark wrote:
    saichand wrote:
    means that uploading files(.doc) or any files by using servlets and jsps
    [http://www.google.com/search?q=How+can+i+upload+files+in+servlets+and+also+using+jsp]
    ~Good topic titles are indeed brilliant search keywords. It's sad to see that it won't even come in the mind of the topicstarters to Google it before posting the topic.

  • How do you register/define servlet to be used in tomcat?

    How do u register/define servlet to be used in tomcat?

    specify servler mapping in web.xml
    <servlet>
        <servlet-name>xxxxx</servlet-name>
       <servlet-class>com.eplus.xxxx.server.ViewUserServlet</servlet-class>
      </servlet>
    <servlet-mapping>
          <servlet-name>xxxx</servlet-name>
          <url-pattern>/xxxx</url-pattern>
      </servlet-mapping>sudhir
    http://www.jyog.com

  • How can I see whatever I print through System.out.println in my servlets when I use iplanet 4.1

    how can I see whatever I print through System.out.println in my servlets when I use iplanet 4.1

    Hi Nitin,
    Look out the below link, Hope this helps you.
    http://knowledgebase.iplanet.com/ikb/kb/articles/4235.html
    http://knowledgebase.iplanet.com/ikb/kb/articles/4790.html
    http://knowledgebase.iplanet.com/ikb/kb/articles/4699.html
    Regards,
    Dakshin.
    Developer Technical Support
    Sun Microsystems
    http://www.sun.com/developers/support.

  • How to run a servlet in eclipse using "SAP Portal Plugin"  ( not tomcat)

    Hi All
    I'm just trying to create a simple servlet in Eclipse using SAP Portal Plugin but I couldn't find any document.
    I have an eclipse 2.1
    EP6 SP2 patch 5
    SAP Portal Plugin
    I created a Portal Application Project.
    I created a simple servlet and save it under src.core directory.
    My question is as follow:
    1) Which directory I should put in the file web.xml?
    2) Do I export this as *.par file?
    3) When I export it. Can I just call the servlet from the url?
    Anyone help.. I really appreciate.
    thanks much.
    Jen

    Hi,
      Portal plugin is used for developing SAP Portal applications ie Java iviews.
    There is a set of procedures to develop Java iViews . You can develop either AbstractPortalComponent which is more or less equivalent of servlet in ordinary java world or JSPDynPage which is equivalent of JSP.
    These plugins are used to develop any of the above portal components. If you are developing java applications for portal then you have to develop either of the above using the tools. These portlets( portal applications runs on Portal run time)
    But servlets can run on J2EE itself.
    But if your requirement is to develop servlet then you can create ordinary java project and deploy that in the J2EE server as like in any app server.
    Regards,
    Abdul Raheem .S

  • How to include servlet in JSP using Include Directive?

    Hi experts,
    am a beginner to JSP.. I want to know,
    is it possible to include a servlet in jsp using include directive? could any one explain me...

    No it is not possible.
    Include directive is like copying and pasting some text into a JSP file, and then translating/compiling it.
    So the only thing you can include with the <%@ include %> directive is a jsp fragment
    It is a static translation/compile time include and thus will always be the same
    By contrast <jsp:include> is a runtime include, and includes the result of running the imported url.
    That URL has to be a complete/standalone jsp/servlet/whatever. However as it is runtime, it can take parameters where the include directive can not.
    Does that answer your homework question?
    Cheers,
    evnafets

  • How to use servlets and JSP for my homepage?

    servlets and JSP are server-side program. If my homepage is on some web-hosting websites, can I upload the servlets and JSP to run it? if possible, where can I find such a web-hosting place?
    sraiper

    Not many hosts offer JSP or Servlet support (and some do but then stop and never give you a refund, grrrrrrr!!!!).
    Also, ones that do support it can often be more expensive. There are some free ones but all the one's I've come across have problems that made them unsuitable for my needs.
    Here is a list of hosts that support Java:
    http://www.thejspbook.com/resources/category.jsp?id=1005&name=JSP+web+hosting
    I can't comment on any from that list, however I use http://www.positive-internet.com they are a bit pricey but they have excellent support and are always happy to help with any Tomcat (the JSP/Servlet server they use)configuration issues or needs that you may have.

  • How to use JDBC Connection Pools in a standalone application?

    Hi, there,
    I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
    for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
    I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
    any hint will be great apprieciated!
    Sam

    To my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.

  • How to use parameter of one web context in another one???

    Hey guys,
    I have a web context which is a servlet
    The other web context is a jsp
    I also have a login page
    In the login page after clicking the submit button the
    control is passed to the servlet.
    The login page passes the username and password
    to the servlet
    i have used doGet() method.
    I simply want to retrieve the parameter present in url of the servlet and use this in the jsp.
    How is this possible??
    To make things clearer , here are the three pages:
    1> Login.html:<HTML>
    {<HEAD>
    <TITLE>
    First Media - DashBoard
    </TITLE>
    </HEAD>
    <BODY>
    <FORM METHOD=GET
    ACTION="http://localhost:8080/Dashboard/Dashboard">//url for servlet
    <IMG SRC="C:\dashboard\Picture1.png"
    ALT="Unable to display picture" ALIGN="LEFT" HEIGHT="150" WIDTH="150">
    <H3>
    <CENTER>
    LOGIN SCREEN
    </CENTER>
    </H3>
    <P></P><P></P>
    <BR><BR><BR><BR><BR>
    <P>
    <H4>
    <CENTER>First Media DashBoard Display</CENTER>
    </H4>
    </P>
    <BR><BR>
    <P>
    <CENTER>
    LOGIN ID ���
    <INPUT TYPE="TEXT" NAME="userid">
    </CENTER>
    </P>
    <BR><BR>
    <P>
    <CENTER>
    PASSWORD ���
    <INPUT TYPE="PASSWORD" NAME="userpass">
    </CENTER>
    </P>
    <BR><BR>
    <INPUT TYPE="SUBMIT" VALUE="SUBMIT">
    </FORM>
    </BODY>
    </HTML>
    Here's the servlet:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    public class Dashboard extends HttpServlet
         public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    out.println("<HTML>");
    out.println("<HEAD><TITLE>FIRST MEDIA DASHBOARD</TITLE></HEAD>");
    out.println("<FRAMESET ROWS=\"20%,80%\">");
    out.println("<FRAME SRC=\"http://localhost:8080/Intro/Intro\">");//this is the url for the jsp
    out.println("<FRAMESET COLS=\"20%,80%\">");
    out.println("<FRAME SRC=\"c:/dashboard/MainNetwork.html\" NAME=\"mainframe\">");
    out.println("<FRAME SRC=\"c:/dashboard/DisplayArea2.html\" NAME=\"displayframe\" SCROLLING=\"NO\">");
    out.println("</FRAMESET>");
    out.println("</FRAMESET>");
    out.println("</HTML>");
    Finally the jsp :
    <HTML>
    HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Hide from tired old browsers
    function multiLoad(doc1,doc2) {
    parent.mainframe.location.href=doc1;
    parent.displayframe.location.href=doc2;
    // -->
    </SCRIPT>
    </HEAD>
    <BODY>
    <IMG SRC="C:\dashboard\Picture1.png"
    ALIGN="LEFT" WIDTH="80" HEIGHT= "80">
    <BR>
    Network Log
    ���������
    Service Levels
    ���������
    <A HREF="# onClick=
    "parent.location='http://localhost:8080/Dashboard/Login.html';
    window.location='C:\dashboard\Login.html';">LogOut
    </A>
    <H3>
    <%
    if (request.getParameter("userid") == null)
         out.println("Welcome to dashboard");
    else { 
    out.println("Hello," + request.getParameter
    ("userid"));
    } %></H3>//code to try to greet the user by name
    </BODY>
    </HTML>
    I know this is a long one, but guys, please help!!!
    Message was edited by:
    alok1983
    Message was edited by:
    alok1983
    Message was edited by:
    alok1983
    Message was edited by:
    alok1983

    If you re-post using the code tags to format the message some one may actually take the time to read it.

Maybe you are looking for