• Как связать сервлет и JSP?

    @karthickvarunan
    You can send request parameters straight into a a bean, without scripting: The html code:
    
    <form action="TestBean.jsp">
        name: <input type="text" name="userName">
        ID#: <input type="text" name="userID">
        <input type="submit">
    </form>
    Inside TestBean.jsp:
    
    <jsp:useBean id="person" type="foo.Person" class="foo.Employee">
        <jsp:setProperty name="person" property="name" param="userName">
    Note that param attribute: the param value comes from the name attribute of the form input field.
    
    It can be simplified further, though I don’t know if that is a good idea, by following some conventions:
    
    // abstract class foo.Person
    String getName();
    void setName();
    
    // foo.Employee extends foo.Person
    int getEmpID()
    void setEmpID(int)
    Now the HTML needs to be (basically BOTH parameters matches the property name of the bean):
    
    <form ...>
        name: <input type="text" name="name">
        ID#$: <input type="text" name="empID">
        ...
    </form>
    Then we get to do this:
    
    <jsp:useBean ... >
        <jsp:setProperty name="person" property="*" />
    Note that only String and primitives are converted automatically.


    for
    servlet example programs
    Ответ написан
    Комментировать
  • Жизненный цикл servlet'ов в Tomcat'e?

    @karthickvarunan
    A servlet life cycle can be defined as the entire process from its creation till the destruction. The following are the paths followed by a servlet.

    The servlet is initialized by calling the init() method.
    The servlet calls service() method to process a client's request.
    The servlet is terminated by calling the destroy() method.
    Finally, servlet is garbage collected by the garbage collector of the JVM.

    for servlet tutorial
    Ответ написан
    Комментировать
  • Можете посоветовать книгу по Java для написания сайтов?

    @karthickvarunan
    looking forward to learning java from the experts. Then I will recommend this tutorial site for further

    java example programs
    Ответ написан
    Комментировать