Free download head first jsp and servlets pdf




















This book will get you way up to speed on the technology you'll know it so well, in fact, that you can pass the brand new J2EE 1. If that's what you want to do, that is. Maybe you don't care about the exam, but need to use servlets and JSPs in your next project.

You're working on a deadline. You're over the legal limit for caffeine. You can't waste your time with a book that makes sense only AFTER you're an expert or worse, one that puts you to sleep. Learn how to write servlets and JSPs, what makes a web container tick and what ticks it off , how to use JSP's Expression Language EL for short , and how to write deployment descriptors for your web applications.

Master the c:out tag, and get a handle on exactly what's changed since the older J2EE 1. You don't just pass the new J2EE 1. Head First Servlets and JSP doesn't just give you a bunch of facts to memorize; it drives knowledge straight into your brain. You'll interact with servlets and JSPs in ways that help you learn quickly and deeply.

And when you're through with the book, you can take a brand-new mock exam, created specifically to simulate the real test-taking experience.

Score: 4. All Users. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn't always want to take in the dry, technical stuff you're forced to study. The fact is your brain craves novelty. It's constantly searching, scanning, waiting for something unusual to happen. After all, that's the way it was built to help you stay alive.

It takes all the routine, ordinary, dull stuff and filters it to the background so it won't interfere with your brain's real work--recording things that matter. How does your brain know what matters? It's like the creators of the Head First approach say, suppose you're out for a hike and a tiger jumps in front of you, what happens in your brain? Neurons fire. Emotions crank up. Chemicals surge. That's how your brain knows. And that's how your brain will learn Java.

Head First Java combines puzzles, strong visuals, mysteries, and soul-searching interviews with famous Java objects to engage you in many different ways. It's fast, it's fun, and it's effective.

And, despite its playful appearance, Head First Java is serious stuff: a complete introduction to object-oriented programming and Java. March Second Edition. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. While every precaution has been taken in the preparation of this book, the publisher and the author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.

Readers of this book should be advised that the authors hope you remember them, should you create a huge, successful dotcom as a result of reading this book. Who is this book for? How many GUI apps do you know that are used by millions of users worldwide? As a web app developer, you can free yourself from the grip of deployment problems all standalone apps have, and deliver your app to anyone with a browser.

But you need servlets and JSPs. Because plain old static HTML pages are so, well, Learn to move from web site to web app. Exam objectives 2 What web servers and clients do, and how they talk? When a request comes in, somebody has to instantiate the servlet or at least allocate a thread to handle the request.

Somebody has to get the request and the response to the servlet. Somebody has to manage the life, death, and resources of the servlet. Exam Objectives 38 What is a Container and what does it give you? Time to build it, deploy it, and test it. Next, you need to set up your deployment environment following the servlet and JSP specs and Tomcat requirements. True, this is a small app And your servlet code has to know how to send a response.

Or not You have models, controllers, and views. You have parameters and attributes. You have helper classes. But how do you tie the pieces together? How do you let components share information? How do you hide information?

How do you make information thread-safe? Your job may depend on the answers. As soon as they send you a response, they forget who you are. But sometimes you need to keep conversational state with the client across multiple requests. You can write Java code in your JSP, but should you? And if not Java code, what do you write? How does it translate into Java code? Do your web page designers really have to know Java?

Do they expect server-side Java programmers to be, say, graphic designers? But there are some traps Sometimes EL behaves differently than if you used the same syntax in Java, so pay attention! Exam Objectives When attributes are beans Standard actions: useBean, getProperty, setProperty Can you make polymorphic bean references? What if you want to loop through the data in an array, and display one item per row in an HTML table?

You know you could write that in two seconds using a for loop in a scriptlet. No problem. That way, your page designers can use your tag in their pages, while all the hard work is done behind the scenes in your tag handler class. Of the three, two were introduced with JSP 2. Your pages are polished, your code is tested and tuned, and your deadline was two weeks ago. But where does everything go? So many directories, so many rules.

What do you name your directories? What does the client actually request, and how does the Container know where to look? Exam Objectives Key deployment task, what goes where? Trouble lurks in every corner of the network. Does Jim in marketing really need to know that Lisa in engineering makes three times as much as he does? And if you can intercept the request, you can also control the response. And best of all, the servlet remains clueless. What does that mean to you? More vacations.

Want to add user request tracking to every servlet in your app? Manipulate the output from every servlet in your app? Exam Objectives Hardware and software forces behind patterns Review of softweare design principles MVC Yes! This is it. We know. Sometimes you need more than EL or standard actions.

The JSTL 1. Having access to 9. JSTL v1. URL-related: url. That means each web app needs a copy. I want to show one element per row in a table EL and standard actions are limited What happens when you bump into a brick wall? Developers usually want way more standard actions or—even better—the ability to create their own actions.

And you can. For the JSP page creator, custom tags are much easier to use than scripting. For the Java programmer, however, building the custom tag handler the Java code invoked when a JSP uses the tag is tougher. Still, there could be times when you need something from, say, a custom tag library developed specifically for your company.

What we need is a way to convert those angle brackets into something the browser will render as angle brackets, and there are two ways to do this.

A c:out tag without an escapeXML attribute is just the. She noticed that we were using EL everywhere to output strings entered by users. She said this was a security risk and recommended we output all user strings using the c:out tag.

What gives? A: Your consultant was right. The security risk she is referring to is called cross-site hacking or cross-site scripting. The cracker includes viral JavaScript code in the comment. This previnterpreted by A: Good question.

The c:out tag is smart, and it recognizes when the value is null and can perform a special action. That action is to provide a default value Just add a default attribute, and provide the value you want to print if your expression evaluates to null: This value is output if the value attribute evaluates to null. Servlet code Mak e a St set the arrring[] of movie names, ay as a requ est attribuatnd e. This table has element in a ne per row.

The trick is telling the table how many rows and columns you want. The key feature is that the tag assigns each element in the collection to the variable you declare with the var attribute.

The variab value changes with each iter collection. An array of arrays? In this example, we put String arrays into an ArrayList, then make the ArrayList a request attribute. The JSP has to loop through the ArrayList to get each String array, then loop through each String array to print the actual elements of the array.

ArrayList ; movieList. Watch it! No fou r— ibutes like the other book tells you where to get the specs covered on the to which you can bind attr ses sio n, and application. Tag scope exam. And imagine that members can also post comments, but non-member guests cannot.

What if you want to do one thing if the condition is true, and a different thing if the condition is false? In other words, what if we want to show either one thing or the other, but nobody will see both? The first But now imagine this scenario: you have a car sales web site, and page asks the user what he you want to customize the headline that shows up on each page, based on a user attribute set up earlier in the session.



0コメント

  • 1000 / 1000