Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam (SCWCD)

Category: Programming
Author: Bryan Basham, Kathy Sierra, Bert Bates
4.3
This Year Stack Overflow 3
This Month Stack Overflow 2

Comments

by anonymous   2019-07-21

I would recommend this book: http://www.amazon.com/Head-First-Servlets-JSP-Certified/dp/0596005407. I found it very helpful while learning JSP.

by anonymous   2019-07-21

Since you are using Java, you should also look into Servlets and JSPs. This will give you a more non-abstract view into the HTTP world. You will understand how it is used at an application level.

If you are into turning pages, I suggest http://www.amazon.com/Head-First-Servlets-JSP-Certified/dp/0596005407

If you want online tutorials you can find them by googling "Servlet and jsp tutorials".

An overview can be found here
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Overview.html

by anonymous   2017-08-20

As to your problem, anything which you declare locally using the old fashioned scriptlets is not linked with a jsp:useBean. Also, declaring a local scriptlet variable is not visible in the included pages, you need to explicitly put them in at least the request scope. As using scriptlets is a bad practice. I recommend to forget about it at all.

In your specific case, just create a real java bean to hold the data. That is, a class with an (implicit) default constructor and private properties which are exposed by public getters/setters. Here's a basic example:

public class User {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

Then you can use a servlet class to preprocess requests. You can use servlet's doGet() method for this.

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    User user = new User();
    user.setName("Jitendra");
    request.setAttribute("user", user); // Store in request scope.
    request.getRequestDispatcher("/WEB-INF/show.jsp").forward(request, response);
}

Map this servlet in web.xml on an url-pattern of for example /show. This servlet should then be accessible by http://example.com/context/show and its doGet() would be executed immediately.

Then change/create the JSP file show.jsp which you place in /WEB-INF to prevent from direct access (so that clients cannot access it by http://example.com/context/show.jsp but are "forced" to call the servlet) with the following line:

<p>User name: ${user.name}</p>

The ${user} refers to the object which is associated with any request/session/application attribute key user. This does behind the scenes jspContext.findAttribute("user"). As the returned User instance conforms the javabean spec, the ${user.name} will invoke the getName() method on the User instance and the EL will display its outcome.

Oh, I should add, you do not need jsp:useBean for this as the servlet has already created and put the desired bean in the scope.

That said, I recommend to start with a decent JSP/Servlet tutorial/book. Examples:

Hope this helps.

by anonymous   2017-08-20

Use JSTL, as @CoolBeans says. It would look something like this:

In the servlet,

// where myBean is an instance of the class with [get|set]Title
request.setAttribute("myFoo", myBean);

Then, in the JSP,

<c:choose>
    <c:when test="${myBean.title eq 'P'}">Peer</c:when>
    <c:when test="${myBean.title eq 'T'}">Team</c:when>
</c:choose>

If you're not familiar with JSTL, I'd recommend reading through the JSP section of the Java EE 5 Tutorial, or picking up a copy of Head First Servlets and JSP (it's quite good).

by anonymous   2017-08-20

Yes. It is certainly possible, I assume you have been developing most Desktop Application and native Software using Java and so would advise to take up some JSP and Servlets knowledge to dive into web development.

  1. Books for Web Application Development
  2. JSPs and Servlet - Head First Series is good book to start.
  3. Don't Make me thing good book on understanding UI stuffs, which is important for Web Designers.

Try to browse through web-development tags as you will find very useful suggestions there.