Figure 3 Create login.jsp through wizard |
Figure 4 JSP file created by the wizard |
Figure 5 Set JSP tag attribute editor |
1. <%@page contentType="text/html; charset=GBK" %> 2. <html> 3. <head> 4. <title>login</title> 5. </head> 6. <body bgcolor="#ffffff"> 7. <Form name="Form 1" method="post" action="switch.jsp"> 8. User name: <select name="userId"> 9. <option value="" selected>--Login user--</option> 10. <option value="100000">Jiang Ziya</option> 11. <option value="100001">Bao Shuya</option> 12. <option value="100002">Vertical teeth</option> 13. </select> 14. Password: <input name="password" type="password"> 15. <input type="submit" name="Submit" value="Login"> 16. </form> 17. </body> 18. </html> |
Figure 6 login.jsp entry page |
Practical experience: The JSP file code contains static and dynamic parts, that is, one part is HTML code, and the other part is JSP tags and Scriptlet code. JSP is generally a web page with dynamic logic. JBuilder supports dynamic code parts such as JSP tags and Scriptlets very well. You can use tools such as CodeInsight and TagInsight to complete coding quickly and correctly, and you can also compile and debug JSP. In terms of JSP static HTML code writing and visual design, JBuilder seems to be inadequate. Dreamweaver is obviously better than JBuilder in static code and visual design. |
1. package bookstore; 2. import java.sql.*; 3. 4. public class UserList 5. { 6. //Get the user list code of the HTML drop-down box 7. public static String getUserListHTML() { 8. Connection conn = null; 9. StringBuffer sBuf = new StringBuffer(); 10. try { 11. conn = DBConnection.getConnection(); 12. PreparedStatement pStat = conn.prepareStatement( 13. "select USER_ID,USER_NAME from T_USER"); 14. ResultSet rs = pStat.executeQuery(); 15. while (rs.next()) { 16. sBuf.append("<option value='" + rs.getString("USER_ID") + "'>" + 17. rs.getString("USER_NAME") + "</option>n"); 18. } 19. return sBuf.toString(); 20. } catch (SQLException ex) { 21. ex.printStackTrace(); 22. return ""; 23. } finally { 24. try { 25. if (conn != null) { 26. conn.close(); 27. conn = null; 28. } 29. } catch (SQLException ex1) { 30. } 31. } 32. } 33. } |
Figure 7 Writing code through CodeInsight |
1. <%@page contentType="text/html; charset=GBK" import="bookstore.UserList" %> 2. <html> 3. <head> 4. <title>login</title> 5. </head> 6. <body bgcolor="#ffffff"> 7. <Form name="Form 1" method="post" action="switch.jsp">User name: 8. <select name="userId"> 9. <option value="" selected>--Login user--</option> 10. <%=UserList.getUserListHTML()%> 11. </select> 12. Password: <input name="password" type="password"> 13. <input type="submit" name="Submit" value="Login"> 14. </form> 15. </body> 16. </html> |
Figure 8 Running login.jsp in JBuilder |
Figure 9 Use IE to access login.jsp running in JBuilder |
hint: Since compiling a JSP file requires first converting it into a Servlet file, and then compiling the intermediate Servlet file. If an error occurs, it will be redirected to the JSP file. Therefore, compiling a JSP file is more time-consuming and often takes longer than compiling a Java file. Several times the time. By default, when compiling a project, all JSPs in the entire project will be compiled, which takes a lot of time. Therefore, it is best to cancel the setting of compiling JSP files together with the compilation project: through Project->Project Properties...->Build-> cancel the Check JSPs for errors at build-time option in the Build settings page. Check this option when you really need it, and cancel this option immediately after compilation. This setting will buy you a lot of valuable time in development. |