Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam
All
Stack Overflow 17
This Year
Stack Overflow 1
This Month
Stack Overflow 3
install apache tomcat on your server, use a sql database and use json for communication. For the rest: Do you know google? Its a nice search engine. You find it at google.com
I like this book for beginning with servlets / tomcat:
http://www.amazon.de/Head-First-Servlets-Bryan-Basham/dp/0596516681/ref=sr_1_2?ie=UTF8&qid=1353091543&sr=8-2
Head First Servlets and JSP covers the topic very comprehensively and gently. The 2nd edition was published in 2008 and AFAIK there have been little or no changes to the JSP spec since then.
Although this book covers both Servlets and JSPs, in most environments where JSPs are being used, Servlets (or something similar like Struts actions) are also used. Because JSPs are Servlets at runtime, it could be argued that understanding Servlets is a pre-requisite for understanding JSPs.
I'm supposing here that you have a good understand of java programming.
Fisrtly, I think you should understand java for web. I recommend this book:
Head First Servlets and JSP http://www.amazon.com/Head-First-Servlets-JSP-Certified/dp/0596516681/
Then you can learn web services with java:
Java Web Services: Up and Running http://www.amazon.com/Java-Web-Services-Up-Running/dp/1449365116
Of course, there are many tutorials over the internet as well, but books give you a lot of background information.
The answer is - Yes, you can.
OK, besides the JB Nizet's comment here are a few suggestions.
1) Have you added your init parameters while the Web Container / Application Server was running?
Quote from "Head First Servlets & JSP: Passing the Sun Certified Web Component Developer Exam":
2) There are two types of init parameters available. Another quote from "Head First Servlets and JSP" (emphasis mine):
Example:
getServletContext().getInitParameter(“email”);
getServletConfig().getInitParameter("name");
An alternative way of getting servlet init parameter is using a method defined in the abstract class GenericServlet:
public String getInitParameter(String name);
This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig object.
And there is also
Enumeration<String> getInitParameterNames()
method for both ServletContext and ServletConfig to get all init parameters.There are several mechanisms for reusing content in a JSP page.
The following 4 mechanisms to include content in JSP can be categorized as direct reuse:
(for the first 3 mechanisms quoting from "Head First Servlets and JSP")
Tag File is an indirect method of content reuse, the way of encapsulating reusable content. A Tag File is a source file that contains a fragment of JSP code that is reusable as a custom tag.
The PURPOSE of includes and Tag Files is different.
Tag file (a concept introduced with JSP 2.0) is one of the options for creating custom tags. It's a faster and easier way to build custom tags. Custom tags, also known as tag extensions, are JSP elements that allow custom logic and output provided by other Java components to be inserted into JSP pages. The logic provided through a custom tag is implemented by a Java object known as a tag handler.
Some examples of tasks that can be performed by custom tags include operating on implicit objects, processing forms, accessing databases and other enterprise services such as email and directories, and implementing flow control.
Regarding your Edit
Maybe in your example (in your Edit), there is no difference between using direct include and a Tag File. But custom tags have a rich set of features. They can
Be customized by means of attributes passed from the calling page.
Pass variables back to the calling page.
Access all the objects available to JSP pages.
Communicate with each other. You can create and initialize a JavaBeans component, create a public EL variable that refers to that bean in one tag, and then use the bean in another tag.
Be nested within one another and communicate by means of private variables.
Also read this from "Pro JSP 2": Understanding JSP Custom Tags.
Useful reading.
Difference between include directive and include action in JSP
JSP tricks to make templating easier
Very informative and easy to understand tutorial from coreservlet.com with beautiful explanations that include
<jsp:include> VS. <%@ include %>
comparison table:Including Files and Applets in JSP Pages
Another nice tutorial from coreservlets.com related to tag libraries and tag files:
Creating Custom JSP Tag Libraries: The Basics
The official Java EE 5 Tutorial with examples:
Encapsulating Reusable Content Using Tag Files.
This page from the official Java EE 5 tutorial should give you even more understanding:
Reusing Content in JSP Pages.
This excerpt from the book "Pro JSP 2" also discuses why do you need a Tag File instead of using static include:
Reusing Content with Tag Files
Conclusion
Use the right instruments for the concrete task.
Use Tag Files as a quick and easy way of creating custom tags.
As for the including content in JSP (quote from here):
Just create one yourself. Any folder which you create in
Tomcat/webapps
will become a standalone webapplication. You don't even need to name it explicitly/examples
. You can even name it/beer
. You then just have to change the URL from http://localhost:8080/examples to http://localhost:8080/beer.That said, I think it's better to look for a more recent book than the one mentioning Tomcat 4.0 which is already over a decade old. There might be more old fashioned advices/practices in the book which really can't be done anymore nowadays (for example, cough, scriptlets). Those books are more recent (in order from newest to older):
To learn JSP/Servlets online, I can recommend the tutorials and ebook at coreservlets.com:
See also:
The
web.xml
file is just a configuration file which instructs the application server under each which filters/servlets to load and instantiate and on which url-patterns those should be invoked.The
context.xml
is just another configuration file which instructs the application under each where the webapp is located at the local storage system and on which domain/URL context it should listen.The appserver parses both files on startup and takes actions accordingly.
It's unclear what your own definitions of "Java EE application" and "Generic Java Web application" are. To answer such a question (even though yourself), you'll need to lookup and/or redefine the definitions. But in general, there are two kinds of Java EE applications: web applications (usually to be deployed in flavor of WAR's) and enterprise applications (usually to be deployed in flavor of EAR's). The major difference is that the second involves EJB's and thus require to be run on an application which supports EJB's (e.g. Tomcat doesn't).
Those are just terms which are been applied dependent on the purpose (and history) of the class in question. The term "POJO" is a (generally negative) term representing a Javabean which is just a value object (totally no business logic, pure bean with only getter/setter methods) and is generally a model object which is part of a "legacy" program which uses EJB/Hibernate. Some call it VO (Value Object), others call it DTO (Data Transfer Object), again others just stick to "javabeans".
Start with Head First Servlets & JSP. Read the Servlet API and try to implement one yourself. Knowledge of HTTP is however mandatory as well. Read/debug/play/hack the source of existing open source Servlet API implementations (e.g. Tomcat). Read/debug/play/hack the source of existing open source (MVC) frameworks (e.g. JSF). Try to understand how they works and then try to do it better. For the learning path ("What skills do I need?") I've posted a similar answer before here.
I would start by taking a look at servlets and JSP. I found this book helpful when I read it: Head First Servlets and JSP
After reading the official tutorial. Think of getting a copy of Head First Servlet and JSP. Servlet and related techs would become handy after reading this.
You shouldn't construct HTML in the servlet. Do it in the JSP. You can use JSTL to control the page flow in JSP page. Just drop jstl-1.2.jar in
/WEB-INF/lib
and declare the taglibs as per the aforelinked TLD documentation.You can use the
<c:if>
or<c:choose>
tag to introduce a condition in the page flow. You can use the<c:forEach>
tag to iterate over an array or a collection in JSP. Your functional requirement is pretty vague, but here's a kickoff example:Pretty straightforward, isn't it? You actually don't need a servlet here, unless you want to preprocess the rows/cols and implement some validation/business logic. Just change the form action to the servlet URL and let the servlet forward the request to the JSP using requestdispatcher which was already explained to you in several answers before. Don't process the HTML in Servlet. There's no need to do that.
After all, you really need get yourself through some basic JSP/Servlet tutorials/books first instead of stabbing around in the dark. You can find excellent online JSP/Servlet tutorials here and you can find good books here and here. Leave your project aside and concentrate you on actually learning the stuff.