Friday, February 28, 2014

Connect database using Servlet & JSP in java web project


  • First, need to copy JDBC drivers into WEB-INF\lib folder. It will come up under "Web App Libraries" automatically.






































  • Second, create a java class for connecting to SQL Server database. 


























  • Third, create Servlet.























  • Fourth, create JSP page.





















Thursday, February 27, 2014

Developers Rank Best Application Servers

Developers Rank Best Application Servers: WebSphere, Apache Geronimo, Windows Server Top List

What's the best all-around application server? According to an Evans Data survey, developers rank IBM WebSphere, Apache Geronimo and Windows Server at the top of the list.

CIO — The "user's choice" for application servers, according to more than 700 software developers, include two of the oldest—one might say mature—and one relative newcomer. Developers ranked IBM WebSphere, the open-source Apache Geronimo and Windows Server among their favorite options, according to a free reportdistributed by Evans Data (free registration required).

Enterprise software developers are, perhaps, all too familiar with application servers: server-based software that can be called by client applications. Web servers are a subset which exclusively handle HTTP requests; in contrast, application servers can use any number of protocols to serve business logic to programs.
Evans Data interviewed more than 700 developers, asking them to rate 21 characteristics of application servers that they had personally used. Among the features and capabilities rated were performance, security features, database connectivity, scalability, support, diagnostics, event logs, and value to cost ratio.
In this survey, Adobe ColdFusion, Red Hat JBoss and Sun Java System Application Server/GlassFish also earned high marks from their users. SAP NetWeaver was also evaluated for their niche uses. And then there's WebLogic....
IBM's WebSphere ranked at the top in 10 of the 21 categories, including those which were identifies as being the most important to developers: performance, scalability, support and diagnostics.
Microsoft's Windows Server is used both as an operating system and as an application server, with its native support for ASP.NET Web development and Web Services technologies such as XMLSOAPUDDI (Universal Description, Discovery and Integration), and WSDSL (Web Services Description Language). In this survey, Windows Server garnered good marks across the board, but delivered the most satisfaction for its database connectivity, support and performance.
But Windows Server is beat out by a candidate from the open-source community: Geronimo, from the Apache Software Foundation. "As an open source program, Geronimo might have been burdened by the perception amongst users of a lack of support," says the report, because open-source software is often criticized by developers for its tech support qualities (or lack thereof). "However, this was not the case with Geronimo, and much of that has to do with IBM. IBM has provided resources and support in a variety of ways to Geronimo and the Apache Software Foundation, including technical support." As a result, Geronimo earned second place marks for quality of support, right behind IBM WebSphere. It also gets top marks from developers for performance and database connectivity.
Another open-source success, JBoss, was marked as delivering the best value to cost ratio, the best compatibility with other software and the best security—all of which matter particularly for enterprise software development.

Original link:
http://www.cio.com/article/455845/Developers_Rank_Best_Application_Servers_WebSphere_Apache_Geronimo_Windows_Server_Top_List?page=1&taxonomyId=3038

Comparison of application servers


Comparison of application servers



The most popular HTTP server Apache and web develop tool Mono

Apache

The Number One HTTP Server On The Internet

  • The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.
    Apache httpd has been the most popular web server on the Internet since April 1996, and celebrated its 17th birthday as a project this February.
    The Apache HTTP Server ("httpd") is a project of The Apache Software Foundation.

Mono (software)

Mono is a free and open source project led by Xamarin (formerly by Novell and originally by Ximian) to create an Ecma standard-compliant, .NET Framework-compatible set of tools including, among others, a C# compiler and a Common Language Runtime.The stated purpose of Mono is not only to be able to run Microsoft .NET applications cross-platform, but also to bring better development tools to Linux developers.[3] Mono can be run on many software systems including Android, most Linux distributions,BSDOS XWindowsSolaris, and even some game consoles such as PlayStation 3Wii, and Xbox 360.The logo of Mono is a stylized monkey's face, mono being Spanish for monkey.[4][5]

Sunday, February 23, 2014

SQL Server - Server Roles

Sometimes your can find your answer in the old version of software like SQL Server Server Roles:


Monday, February 17, 2014

Things you should know using eclipse and Tomcat


  1. You should stop Tomcat service when you want to test your jsp within eclipse as you will run Tomcat within eclipse.
  2. Eclipse doesn't always display everything. It should copy all files from the project folder to a Tomcat work directory, but it doesn't! It tends to “lose” CSS files and images. This means that, except for a quick check of simple features, you might do what I do and use Tomcat externally. To see the output of the test project outside Eclipse, first of all, stop the “internal” Tomcat by rightclicking it under the Servers tab of the Workbench and selecting Stop. Then, start the Tomcat service in Windows. Right-click the test-project folder as you did to launch it within Eclipse, but this time select Export WAR File. When the WAR Export screen appears, the only thing you have to do is browse to select the destination, which should be %CATALINA_HOME%\webapps\test.war, and click Finish. In a browser, type http://localhost:8080/test to see the output of the project. This works because, as I showed to you at the end of the previous section, Tomcat automatically expands all WAR files it discovers in its webapps folder, without any need to restart it. And because by default Tomcat looks for index.html, index.htm, and index.jsp. If you want, you can change the default by adding the following element to the body of the web-app element of web.xml: <welcome-file-list>
                           <welcome-file>whatever.jsp</welcome-file>
                  </welcome-file-list>
  3. You can export WAR file to Tomcat folder, you also can import WAR file to eclipse workplace.

Wednesday, February 12, 2014

Deploy eclipse web project to Tomcat


1. Export web project to WAR file.






















2. Go to Tomcat Manager page, select WAR file and click "Deploy" button.














Tuesday, February 11, 2014

How to display all the session variables in an HTML page?

The session implicit object is an instance of javax.servlet.http.HttpSession. This variable is only valid for Http protocols. The session is one of the JSP built-in variables (like request) that is available in the service body of a JSP. 
There's no way you can do it directly from plain HTML since HTML is static and the session object really "lives" in the dynamic environment of the web container. The following example JSP shows you how to generate HTML that shows the objects in the session attribute collection.
<%@ page language="java" import="java.util.*" %>
<html>
<body>
Session attributes:
<%
  session.setAttribute("test.name", "Test Attribute List");
  session.setAttribute("test.float", new Float(5.0));
  session.setAttribute("test.int", new Integer(10));
  session.setAttribute("test.Object", new StringBuffer("StringBuffer"));
  session.setAttribute("test.boolean", new Boolean(true));
  session.setAttribute("test.double", new Double(343.1));
  for (Enumeration e = session.getAttributeNames(); e.hasMoreElements(); ) {     
    String attribName = (String) e.nextElement();
    Object attribValue = session.getAttribute(attribName);
%>
<BR><%= attribName %> - <%= attribValue %>

<%
}
%>
</body>
</html>

Original link: 
http://www.xyzws.com/JSPfaq/how-to-display-all-the-session-variables-in-an-html-page/33

Monday, February 10, 2014

How to use HttpSession




HttpSession getSession()  

          Returns the current session associated with this request, or if the request does not have a session, creates one.  
   
  
HttpSession getSession(boolean create)  
          Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.


Sunday, February 9, 2014

Installing the BIRT Viewer in Tomcat


BIRT POJO Viewer

Starting with the release of BIRT 3.7 the Viewer has been changed to be POJO based. All required BIRT plugins are now in the WEB-INF/lib folder of the Viewer, and the WEB-INF/platform directory has been removed. The Viewer should continue to operate as in previous versions of BIRT. More information about this change is available in the BIRT 3.7 Migration Guide.

Using Tomcat

This page explains how to deploy the BIRT viewer to a Java EE container. We'll useApache Tomcat, since it is open source and readily available. The same concepts, perhaps with different details, apply to other app servers. These instructions assume you'll install Tomcat on your own machine using the default port number of 8080.

Install the Viewer

Deploy the BIRT Viewer application. Follow these steps:
  • Download the zip file with the BIRT report engine runtime. The file is named birt-runtime-version#.zip.
  • Unzip the file in a staging area.
  • Look under the birt-runtime- directory and locate the "Web Viewer Example" directory.
  • Copy the Web Viewer Example directory to the webapps directory of your Tomcat installation. For ease of reference, rename the directory to "birt-viewer".
  • Stop, then restart Tomcat.
  • Display the Tomcat manager application to check that the viewer is deployed:http://localhost:8080/manager/html.
  • Verify that birt-viewer is listed as an application, then click on the birt-viewer link.
  • A page confirming that the BIRT viewer has been installed should be displayed. Click on the link labeled "View Example" to confirm that your installation is working properly.
  • The BIRT Viewer requires that cookies be enabled.
If you choose to put the Viewer into some other location, you'll need to use a context entry within the server.xml file to indicate the deployment location. See Tomcat documentation for details.

Install your JDBC Drivers

Add the jar files for your JDBC drivers to the Viewer. Copy the driver the following directory:

BIRT JDBC Driver Location Note:

    If you are installing BIRT 2 series the driver needs to be copied to birt-viewer\WEB-INF\platform\plugins\org.eclipse.birt.report.data.oda.jdbc\drivers directory.
    If you are installing BIRT 3.7 or higher, the jdbc driver should be placed in the WebViewer's classpath (eg WEB-INF/lib).

Testing a More Complex Report

We'll test the viewer further using one of the example reports created for the "Classic Models" database. Note that Classic Models database is included in the birt runtime distribution so no further set-up is required. Follow these steps:

Thursday, February 6, 2014

How to check the html button request value using JSP

Below shows you how to check the html button request value using JSP:



















JSP file:
<html>
<head>
  <title>E-bookshop</title>
  <style type="text/css">
    body {background-color:gray; font-size=10pt;}
    H1 {font-size:20pt;}
    table {background-color:white;}
    </style>
  </head>
<body>
  <H1>Your online Bookshop</H1>
  <hr/><p/>
<form name="addForm" method="POST">
      <input type="hidden" name="do_this" value="add">
      Book:
      <select name=book>
<option>Learn HTML5 and JavaScript for iOS. Scott Preston $39.99</option>
<option>Java 7 for Absolute Beginners. Jay Bryant $39.99</option>

</select>
      Quantity: <input type="text" name="qty" size="3" value="1">
      <input type="submit" value="Add to Cart">
      </form>
    <p/>

      <form name="checkoutForm"  method="POST">
        <input type="hidden" name="do_this" value="checkout">
        <input type="submit" value="Checkout">
        </form>
<br/>
<%=request.getParameter("do_this") %>
</body>
</html>

Tuesday, February 4, 2014

How To Configure An Apple Magic Mouse To Work On A Windows PC

http://thetechreviewer.com/tech-tips/configure-apple-magic-mouse-work-windows-pc/

JSP basic


1. Directive
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.Date" %>

2. Declaration
In JSP, you can declare variables
in three ways:
<% int k = 0; %>
<%! int k = 0; %>
<%! static int k = 0; %>
The first declaration means that a new variable is created for each incoming HTTP client request;
the second one means that a new variable is created for each new instance of the servlet; and the third
one means that the variable is shared among all instances of the servlet.

Normally, Tomcat instantiates each one of these classes only once
and then creates a Java thread for each incoming request. It then executes the same servlet object within
each thread. If the application runs on a distributed environment or for high numbers of requests,
Tomcat can instantiate the same servlet more than once. Therefore, only the third declaration
guarantees that the variable will be shared among all requests.

3. Include another JSP on page
   <jsp:include page="index.jsp"/>

4.Scope
There are four possible scopes. Inorder of increasing generality, they are: page, request, session, and application.

5.Using an Attribute to Enable and Disable Conditional Code
One of the advantages of using JSP is that the web server doesn’t need to reinterpret the source file of a
page every time a client requests that page. The JSP container translates each JSP page into a Java file
and compiles it into a class, but this only happens when you update the JSP source. You might like to be
able to switch on or off some particular functionality for debugging or other purposes, without having to
edit one or more file and force Tomcat to recompile them when you flip the switch. To achieve this
result, you only need to wrap the functionality in question inside a conditional statement, as the

following:




































6. The out Object
The following three lines have exactly the same effect on the response:
<% out.print("abc"); %>
<%="abc"%>
abc

7.MVC
The Model 2 Architecture
A better solution, more suitable for larger applications, is to split the functionality further and use JSP
exclusively to format the HTML pages. This solution comes in the form of the JSP Model 2 architecture,
also known as the model-view-controller (MVC) design pattern (see Figure 3-2).






















Includes another JSP page in a JSP page


The following code includes another JSP page in a JSP page:
...............
<jsp:include page="index.jsp"/>
...............



Monday, February 3, 2014

Java Desktop GUI

http://www.javaguicodexample.com/javadesktopguimysql1.html

How to test your web project in Eclipse

Before you can test your web project, you need to define a new server. Once you define a new server, your eclipse will generate a new server project automatically:
























Change Tomcat default home screen

Tomcat default home screen is located on C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\index.jsp. In order to keep all the default functions you should copy the ROOT folder and change its name to "home", then delete everything in ROOT folder and copy your own files into this folder.





















After this modification you can browse the original home screen by typing:
http://localhost:8080/home

The conf\web.xml file define what kind of file can be the start up screen.
















So you can create a index.jsp, index.htm or index.html file as your startup screen.

Saturday, February 1, 2014

How do I give my computer a static local IP address?

http://www.boutell.com/newfaq/creating/staticlocalip.html

How do I get a hostname for my home computer?

http://www.boutell.com/newfaq/creating/hostnameathome.html

How to install Tomcat in Windows 7, modify port & username & password

Step one: Download Tomcat Windows installer from Tomcat website and execute it.
Step two: Create a new rule in firewall, allow Tomcat server port to be accessible.


Now you should be able to browse Tomcat server page by entering: localhost:8080 on local pc or entering xx.xx.xx.xx:8080 on other pc.

You can also change the server port by modifying the server.xml file:

You can also change the user and password by modifying the tomcat-users.xml file:









How do I give my computer a static local IP address?

Original link: http://www.boutell.com/newfaq/creating/staticlocalip.html

Repost:

2006-01-25: If you are using a router to share your Internet connection with more than one computer in your home, or to achieve wireless Internet access (WiFi), congratulations! Your computers are protected from several common threats. That's because other computers on the Internet can't directly connect to your computers -- the router won't let them.
Normally this is great, but when we want to host a website at home or host BitTorrent downloads at home, it's inconvenient. In these cases, we want other people to be able to connect to our computer... for those purposes only, of course.
You can skip this article if you have no router. If you have wireless networking (wifi), or more than one computer, you definitely have a router and you will definitely need to follow these steps. Occasionally a router is built right into your DSL or cable modem, in which case you will need to look at the manual for that device.
Fortunately, all well-made routers allow us to forward ports to a particular computer inside the "local" network (your collection of computers at home, "behind" the router). Unfortunately, many routers assign a new address to each computer every time it is turned on. To forward connections on web or BitTorrent ports, we first need a "static" (unchanging) local address on the local network to forward those connections to! So how do we keep our computer from getting a new address every time we power it on? That's the question I'll answer here.
static local IP address is not the same thing as a static Internet IP address. Most cable modem and DSL ISPs give you a dynamic Internet IP address - that is, it is subject to change. That's not what I'm talking about here. I'm talking about an address on the little "private" network that exists behind your router, where your personal computers live. Unless you take the steps in this article, addresses on the local network are also subject to change, which prevents you from forwarding ports to them. That's why we set up a static local IP address for your server - so that we can tell the router which local IP address to forward web or BitTorrent traffic to.
Some routers are smart enough to let you forward ports to a computer by itsname instead of itsaddress. If so, you can skip this article. Check under "virtual server" or "port forwarding" to see if yours is that smart. Mine isn't.
There are two ways to solve this problem. If your router is well-designed, it might have a feature that lets you assign a specific, never-changing local IP address to your computer by its name on the local network. That's convenient because you don't have to change settings on the computer itself.
The second way... which is the only way with some routers, like my own SMC Barricade G and the popular Linksys WRT54G... is to assign your computer an IP address outside the range of addresses that your router gives out automatically. By forcing the computer to use a specific IP address, we avoid the problem of receiving a new address every time we power the computer on. In this case we'll make the change in your computer's network settings. But first, we'll want to double-check the range of IP addresses that your router gives out, so that two different computers never get the same IP address.
Warning: setting a static IP address for a laptop can be a pain if you want to use your laptop on someone else's network, such as in a cafe with WiFi. But if you're going to take your computer other places, your BitTorrent or web server will be out of commission for the duration anyway. So what's the bottom line? Follow these steps only on a computer that stays put and stays turned on! Your BitTorrent won't work for anyone if you take the tracker away. Find an older PC, power it up, install Windows XP or Linux on it, make sure to run Windows Update or the equivalent automatically and often, and leave that machine powered up 24/7. You've just built your first server.
I've talked about changing settings on the router. But how do we get access to your router's settings? Almost all routers include a built-in web server that provides a simple way to configure the router. And that's what we'll use. Typically you'll log in at an address like http://192.168.2.1/ (for an SMC Barricade G and many others) or http://192.168.1.1/ (for a Linksys WRT54G and many others), but see the manual for your router to be sure. Hopefully you have already configured your router with an administrative password to keep hackers from changing your settings.
I can't give you exact step-by-step instructions to do this with every router, because every router is different. Keep your router's manual handy as you read this and you'll get there!
Please don't ask me what your router password is! You chose it when you set up your router, or it is still set to the default. If you can't seem to get in, check the manual of your router for more information. There may be a default password, or the default password might be blank. In a worst-case scenario, follow your router's procedure for a hard reset (not just a power cycle -- there is usually a recessed button for this job, see the manual).
Once you have logged in to your router's configuration interface, explore the advanced settings and look for a way to assign a fixed, unchanging IP address for your computer on your local network. Your router may provide a way to do this on a page of settings devoted to DHCP (Dynamic Host Configuration Protocol). Also take note of the range of addresses automatically assigned to computers without a fixed address. Typically this is 192.168.2.100 to 192.168.2.254 or something similar.
Many routers, such as the SMC Barricade G and the Linksys WRT54G, do not have this feature. Don't worry - there's an alternative way to assign a static local IP address and I'll cover that next.
Assign your computer an address outside this range, such as 192.168.2.11 (for the Barricade) or 192.168.1.11 (for the Linksys). It must still be in the same "class C subnet." In other words, it must still begin with 192.168.2. or 192.168.1. if that is what your router's IP address begins with. Also, you may not use an address ending in .255, which is reserved for special "broadcast" messages.
Now reboot your computer. At the Windows command line (Start -> Run -> cmd.exe), the ipconfig command should now report the fixed IP address that you assigned.

If Your Router Doesn't Let You Set Static Local IPs

If your router doesn't allow you to assign fixed local IPs in this way, all is not lost. You can still assign a fixed IP via the Windows Control Panel (or the Macintosh or Linux equivalent). Follow these steps to force your computer to use a fixed IP address:
This is tricky stuff and you can mess up your connection if you do it wrong. So read carefully. If you don't understand something, don't just try things at random... read more instead!
1. Choose an address. It must be in the same "class C subnet" as your router. That is, if your router's web interface is at http://192.168.2.1/ (typical for the SMC Barricade G) or http://192.168.1.1/(typical for the Linksys WRT54G), then you can choose an address where the last of those four numbers is different. The number you choose must be between 2 and 254, and you must choose an address that won't be dynamically assigned to other computers. The DHCP settings page of your router's web interface will tell you what range of addresses are dynamically assigned by DHCP. Many routers, including both the SMC Barricade G and the Linksys WRT54G, are set up "out of the box" not to assign addresses ending in a number between .2 and .99. So anything in that range is a good choice for your server. For instance, with my SMB Barricade G, 192.168.2.11 is a good choice for a static local IP. With the Linksys WRT54G, 192.168.1.11 is a good choice.
2. Access the Network Connections control panel of Windows XP (Start -> Control Panel -> Network Connections). Pick the connection you're using, either Local Area Connection (for wired Ethernet cables) or Wireless Network Connection (for WiFi). Right-click on that connection's icon and pick Properties. Under "this connection uses the following items," scroll down to "Internet Protocol (TCP/IP)" and double-click on that. The "Internet Protocol (TCP/IP) Properties" window will appear.
3. Right now, "Obtain an IP address automatically" is probably selected. Instead, select "Use the following IP address." In the "IP address:" field, enter the address you chose (for example, 192.168.2.11 works well with my SMC Barricade G, while 192.168.1.11would work well with a Linksys WRT54G). The subnet mask will automatically become 255.255.255.0, which is correct. Set the "Default gateway" field to the address of your router, which is usually 192.168.2.1 (for the Barricade G) or 192.168.1.1 (for the Linksys WRT54G) -- but please don't copy and paste this! Use the address that actually gives you access to the router's web interface.
4. "Use the following DNS server addresses:" is now selected. In the "Preferred DNS server:" field, enter the IP address of your router (the same as the default gateway). Leave "Alternate DNS server:" blank.
5. Click "OK" to leave the "Internet Protocol (TCP/IP) Properties" window, and again to leave the connection properties window. In Windows XP, your IP address will change immediately at this point. Verify that you can still access the Internet. If not, double-check your work.
If you mess up and you're not sure why, you can restore your normal settings by returning to the "Internet Protocol (TCP/IP) Properties" window and re-selecting "Obtain an IP address automatically" and "Obtain a DNS server address automatically."
OK, great, your computer now has a fixed address on the local network. What does that do for us? It gives us a destination for incoming web or BitTorrent traffic. All we have to do now is tell the router what to do with inbound traffic on the ports we've chosen for BitTorrent. For most readers, the next step is to forward ports through the router.

"My server doesn't show up on the client list in my router!"

The "client list" displayed by some routers is just a list of PCs that were assigned addresses dynamically by the built-in DHCP server in the router. You have a static IP address for your server, so it doesn't show up. This is normal, and it's a good thing.