Brief introduction
Pupils can also publish HTML pages on the Internet. However, the primary school page and professional development of the website has a qualitative difference. Web Designers (or HTML developers) must understand colors, users, production processes, page layouts, browser compatibility, image creation, JavaScript, and so on. Designing a nice site requires a lot of work, and most Java developers focus more on creating graceful object interfaces than the user interface. The JavaServer pages (JSP) technology provides a link button for Web designers and Java developers.
If you have developed a large WEB application, you understand the meaning of the word change. Model-View-Controller (MVC) is a design pattern used to help you control changes. MVC weakens the coupling between the business logic interface and the data interface. Struts is an MVC implementation that uses the Servlet 2.2 and JSP 1.1 tags (which belong to the Java EE Specification) as part of the implementation. Although you may never implement a system with struts, knowing that struts may allow you to use some of these ideas in your future Servlet's JSP implementation.
In this article, I'll discuss the pros and cons of the Web page as a starting point for a JSP file, and the elements used in the file may be familiar to you. Then I'll talk about Struts and how it controls changes in your Web project and improves professionalism. Finally, I will be developing this simple JSP file, in the development process I have taken into account the Web design staff and change.
A JSP file is a Java servlet
The JavaServer Page (JSP) file is just another way to look at the servlet. The concept of JSP files enables us to view the Java servlet as an HTML Web page. JSP eliminates the annoying print () statements that often appear in Java code. The JSP file is first preprocessed to a. java file and then compiled to a. class file. If you are using Tomcat, you can view the preprocessed. java file in the work directory. Other containers may store. Java and. class files in other locations; This location is related to the container. Figure 1 illustrates the process from the JSP file to the servlet.
Figure 1. Process from JSP files to servlet
(This is significantly different from Microsoft's Active Server Page (ASP).) The ASP is compiled into memory instead of being compiled into a separate file. )
Simple standalone JSP file
In small JSP applications, it is often seen that data, business logic, and user interfaces are grouped together in a single code module. In addition, the application usually contains logic to control the application process. Listing 1 and Figure 2 show a simple JSP file that allows users to join a mailing list.
Listing 1. Join.jsp--A simple request and response JSP file
<%@ page language= "java"%>
<%@ page import= "business.util.Validation"%>
<%@ page Import= "Business.db.MailingList"%>
<%
String error = "";
String email = request.getparameter ("email");
//Whether there is an e-mail address
if (email!=null) {
//Validate input ...
if (business.util.Validation.isValidEmail (email)) {
//Storage input ...
try {
Business.db.MailingList.AddEmail (email);
catch (Exception e) {
Error = "Error adding email address to system." + E;
if (error.length () ==0) {
%>
//Redirect to welcome page ...
<jsp:forward page= "welcome.html"/>
<%
}
} else {
//Set error message and display page again
Error = email + "Isn't a valid email address, please try again."
}
Else {
email = ";
}"
%>
<title>join mailing list</title>
<body>
<fonT Color=red><%=error%></font><br>
<form action= "join.jsp" name= "Joinform"
<input name= "email" id= "email" value=<%=email%>></ Input>
<input type=submit value= "Submit"
</form>
</body>
/p>