How do I write a JSP file? How to add a database jar package? How do I associate a class file with a JSP file?

Source: Internet
Author: User

How do I add a database jar package?

1. First enter the current workspace, for example: (My workspace is Javaweb)

F:\javaWeb\Web\WebContent\WEB-INF\lib

Then go to the Lib directory and put the jar package into the Lib directory.

2. Then right-click the project: Build path--Configure build path--Library--Add external package--Select the jar package you want to add

Second, how to create and write JSP file?

1. Create a JSP file: Right-webcontent in the project, select JSP file,

2. Write the JSP file:

A. First of all, we will be the JSP source code in the charset,pageencoding, after the text format for Utf-8, sample will not affect the input of Chinese characters

B. In the JSP file

<% embed Java code blocks in HTML, with semicolons appended to each sentence%>

<%= (note that the left side of% and = cannot be separated), output the value of a variable or an expression. There are no branches. %>

C. Give an example here (Create a JSP file, display the contents of the database in the page, and jump pages)

1. For user convenience: We usually write a. properties file to store the load driver and link-driven URLs, usernames, and passwords. As shown

This is the properties file.

This is where our DAO class should be written.

2. After writing the Java.class code, we will start to write the JSP code

<% @pageImport= "com.inba.maya.login.*"%><% @pageImport= "com.inba.maya.dao.*"%><% @pageImport= "java.util.*"%><%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>    <Tablestyle= "Background-color: #999; color: #000; border:1px solid black">        <TRstyle= "Text-align:center; Background-color: #999;">        <TDwidth= "30%">User name</TD>        <TDwidth= "30%">Name</TD>        <TDwidth= "20%">Password</TD>        <TDwidth= "20%">Operation</TD>        </TR>    <% LogindaoLD=newLogindao (); Arraylist<login>List=ld.select (); for (Login l:list) {%><TRstyle= "Text-align:center; Background-color: #FFF;">        <TD><%=l.getusers() %></TD>        <TD><%=l.getname() %></TD>        <TD><%=l.getpassword() %></TD>        <TD><ahref= "loginall.jspid=<%=l.getusers ()%>">Details</a></TD> //Note The Bold section indicates L.getuser () this value to the inside of an interface         </TR>    <%    }    %>    </Table></Body></HTML>
<% @pageImport= "com.inba.maya.dao.*"%><% @pageImport= "com.inba.maya.login.*"%><%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>    <% Strings=request.getparameter ("id"); //Use this method to receive the value from the previous interface (note that the value of wear should not be Chinese, it will be a bug ) Login L=newLogindao (). Select (s); if (s! )= null) {    %>    <Tablestyle= "border:1px solid balck">        <TRstyle= "Background-color: #666; color:red">            <TD>Name</TD>            <TD>User name</TD>            <TD>Password</TD>        </TR>        <TRstyle= "Background-color: #999; color:black">            <TD><%=l.getname() %></TD>            <TD><%=l.getusers() %></TD>            <TD><%=l.getpassword() %></TD>        </TR>    </Table>    <%}else{    %>Sorry, the user was not found! <%    }    %></Body></HTML>

In fact, JSP is the Java code and HTML code mixed together, but the Java code must be written in <%%>

The Java code that you want to output must be written in <=%%>.

How do I write a JSP file? How to add a database jar package? How do I associate a class file with a JSP file?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.