Category:JSP

  • The application object counts all users’ visits to a web page

    Time:2021-1-21

    Because the application object is used to complete the cumulative function, when (1) Current Wen application re deployment(2) Tomcat server restart The counter will restart counting. The JSP code is as follows: Copy codeThe code is as follows: <%@ page language=”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> <meta […]

  • Using cookie and saving Chinese and using cookie to realize shopping cart function

    Time:2021-1-20

    Cookies are some data stored in the client by the server, such as passwords, and some data that you have visited. Set cookie Copy codeThe code is as follows: //Setting cookiesCookie cookie = new Cookie(“TOM”,”111″); //Set the validity period in seconds by defaultcookie. setMaxAge(7*24*60*60); //Add cookie to clientresponse.addCookie(cookie); Get cookies Copy codeThe code is as […]

  • The specific instance of displaying ArrayList to JSP page in action

    Time:2021-1-19

    1、 The ArrayList object obtained from the useraction is filled into the userform, and the JSP page obtains the initial value of the userform.Part of the code of useraction: Copy codeThe code is as follows: private ActionForward executeManageAction(ActionMapping mapping, ActionForm form,   HttpServletRequest request, HttpServletResponse response) {  UserForm userForm = (UserForm)form;  ArrayList userlist = new ArrayList();  […]

  • Seven ways to improve response speed in JSP pages

    Time:2021-1-18

    Method 1: cache data in init () method of servletAfter the application server initializes the servlet instance, it calls the init () method of the servlet before serving the client request. The init () method is called only once in the life cycle of a servlet. By caching some static data in init () method […]

  • Using JSP page to generate random verification code example

    Time:2021-1-17

    checkNum.jsp Copy codeThe code is as follows: <%@ page language=”java” import=”java.util.*,java.sql.*” pageEncoding=”UTF-8″%> <%@ page contentType=”image/jpeg” import=”java.awt.*,java.awt.image.*,javax.imageio.*”%> <% String path = request.getContextPath(); String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”; %> <%! Color getrandcolor (int FC, int BC) / / select colors randomly in a given range{ Random random = new Random(); if(fc>255) fc= 255; if(bc>255) bc= 255; int r= […]

  • Introduction of definition and usage examples in JSP

    Time:2021-1-16

    In JSP, if you need to process complex data, defining a Java method at the top is a very effective solution. The responsibility of processing data is shifted to this method, and then the main process of the JSP page will not be affected. Of course, you can also use js definition method to deal […]

  • IE9 alert block JSP rendering IE8 no problem

    Time:2021-1-15

    Under IE9, JSP rendering may be blocked by alert. No problem under IE8. Problem Description: A JSP that uses jQuery to bind the initialization event ($(function()) of the screen. In the initialization event, there is alert(), In IE8, when alert pops up message dialog box, JSP page is rendered normally in browser; However, in IE9, […]

  • Java output the current date of the system

    Time:2021-1-14

    Copy codeThe code is as follows: package test.remote.tools.combine; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class TestOutDate { public static void main(String[] args) { //method 1 Calendar nowtime = new GregorianCalendar(); String strDateTime=”[“+String.format(“%04d”, nowtime.get(Calendar.YEAR))+”/”+ String.format(“%02d”, nowtime.get(Calendar.MONTH))+”/” + String.format(“%02d”, nowtime.get(Calendar.DATE))+” ” + String.format(“%02d”, nowtime.get(Calendar.HOUR))+”:” + String.format(“%02d”, nowtime.get(Calendar.MINUTE))+”:” + String.format(“%02d”, nowtime.get(Calendar.SECOND))+”.” + String.format(“%03d”, nowtime.get(Calendar.MILLISECOND))+”]”; System.out.println(strDateTime); […]

  • JSP page circulation collection operation arrangement

    Time:2021-1-13

    The first: struts 1.2 loop traversal elements, name is the result set. Reference tag library <% @ taglib URI=“ http://struts.apache.org/tags-logic ” prefix=”logic” %>< logic:iterate >It is mainly used to process the output collection class on the page. Generally speaking, the collection is one of the following:1. Array of Java objects2. ArrayList, vector, HashMap, etcExample: Copy […]

  • Two ways of re encoding data sent by browser by JSP

    Time:2021-1-12

    In recent DRP projects, when using JSP to operate Chinese, there are often some garbled problems. These problems lead to the failure of Chinese input or normal display. Here is about the setting of character set and the encoding method of character set. In JSP / servlet, you can set the encoding in the following […]

  • How to calculate the relative path of JSP

    Time:2021-1-11

    Problem Description: In / JSP/ index.jsp Files use pictures, how to calculate the relative path? How to calculate the relative path after forwarding by servlet and struts? Directory structure: App Name: Demo demo —-webroot —-images —-go.gif —-jsp —-index.jsp —-css —————————————————————————— The first case: direct access to JSP files The URL is http://localhost/Context path/jsp/ index.jsp To […]

  • Discussion on the difference between JSP and Servlet

    Time:2021-1-10

    Answer 1: First of all, you need to understand what a servlet is. A servlet is a java program executed on the server side, but it has a special set of rules (that is, what we usually call the API). JSP simply means a servlet program written with another set of simple rules, which can […]