- Internet & the Web
Designing Webpages in JSP (Java Server Pages):
Step 1: Start Netbean and create a new project
We can press combination of Ctrl+Shift+N as shortcut keys. And there is also a common way go to the File menu and then create a new project see the figure for details. In figures there are some areas which are highlighted to indicate the chosen options. You should select the highlighted options to complete this tutorial.
When you done then you will see the figure 1, and check the highlighted areas from which you can understand which options should be select or choose. When you done then this step press next to go forward…
Project Name and Folder
In this step you will learn how to give a name to your project and where you can save it. See the highlighted areas in the figure 2. In which first is Project Name second is Project Location the last and third is Project Folder. Make changes according to your desire and then click next button to go forward. Commonly we name our projects according to the project type. In website projects you should give it your domain name. For example: if you are designing a website name is xyz.com so your project name should be xyz, from this you will identify your project easily.
In this step you should don’t change anything, leave it as default. And click next button to go forward. We can make changes if you have multiple installed servers for your JSP webpages. JSP webpages runs on glassfish and apache tomcat servers. If you have installed both so you can change the servers from here. And for Java EE version is should be default by your IDE, because when we use IDE for JSP or any other programming platforms we do update to our IDE. That’s why leave it as it is.
And one thing more i would like to increase in your knowledge, that is you can change your server at any time during your development. But it will not a proper way of development. Because it will disturb your settings of pages. It happens sometimes, not usually because if you are working with CSS and HTML so they need their real way of rendering.
We are not going to use any framework, so don’t try to click. Just leave them as they are, click on next button to go forward. There is some techniques to use frameworks in our JSP projects. But in this tutorial I am just focusing the beginners. In future i will give you a useful tutorial about Java frameworks. We use Frameworks to get ease of doing something. And from frameworks our programming security increase. That's why people commonly in Software Companies use framework, because their customers need their product to be complete on time. And the framework will help you to complete and submit the projects on time.
There number of frameworks in JAVA, and they are being used usefully. Because if one thing just designed for your ease and benefit so take advantages from it. As you can see in figure 4, there is a list of frameworks. And if you have idea to work with the help of frameworks then you can select your favorite framework of JAVA.
In this step we will first delete the index.html file and then we will create a new file with extension of index.jsp. We deleted the index.html because I telling you about JSP and it is necessary to change or delete if you got index.html file by default. And you can check if there is by default index.html file, leave it as it is. Create a new file and name it index.jsp and do different actions on both files now run your project so your website will show the index.jsp data on your webpages.
Create a new JSP file
Now we are ready to start programming to design JSP dynamic webpages. I designed a simple page it will show the current date and time. See the coding in listing 1and if you have any kind of problem in JSP tags so you can read my previous article about JSP tags and its uses link: http://naseebqasab.hubpages.com/hub/Introduction-to-Java-Server-Pages
Listing 1: JSP Dynamic Webpages
<%@ page import="java.io.*,java.util.*, javax.servlet.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Dynamic Webpages</title>
<h1>JSP Dynamic Webpages</h1>
Date date = new Date();
out.print("<h4>Hello Hubpages! Date:</h4>"+date.toString());
Here it is the code of the JSP webpage. It is very easy to design webpages using JSP, there are different type of tags in JSP. We can use html normally as we learnt to use them. Just the new technique is to insert the JSP tags. Inside the JSP tags we use Java programming to make our JSP webpages useful. Lets see the output and in the output we will see the current date and time.
Now the webpage is showing the current date and time. If we note the highlighted area so there is localhost and port number. As I told you in previous steps we run the JSP dynamic webpages using severs. I am using apache tomcat on my local machine. That’s why it is written in the address bar localhost:8084. Do your precious comments let me know your ideas about my articles.