Some common problems in JSP

2010-07-14  来源:本站原创  分类:Web  人气:208 

This article describes a few frequently asked questions articles JSP topics, Hashtable and HashMap, the characters into ASCII code, Session, datetime type, to prevent the user directly input url into the page, form the default method is get, point back display page expired, java in Regular use of the page cache does not retain the form request handling Chinese characters, in the JSP page to get the name of the page and so on.

Previously recorded things.

1, character processing request form:

request.setCharacterEncoding ("GB2312")

2, in the JSP page to get the name of the page:

request.getRequestURI (); / / file name
request.getRequestURL (); / / full url

3, the page cache is not retained:

response.setHeader ("Pragma", "No-cache");
response.setHeader ("Cache-Control", "no-cache");
response.setDateHeader ("Expires", 0);

4, date and time (server)

String datestr;
java.text.DateFormat df = new java.text.SimpleDateFormat ("MM dd month day HH: mm E"); / / here format
datestr = df.format (new java.util.Date ());
out.println (datestr);


<% Java.util.Date shijian = new java.util.Date ();%>
<% = Shijian.getYear () +1900 %><%= shijian.getMonth () +1 %><%= shijian.getDate ()%>
<% = Shijian.getHour ()%><%= shijian.getMinute ()%>

5, java in regular use. jdk 1.4 or above is required to import = "java.util.regex .*

6, point back display expired pages

Add the following code in it

<META Http-equiv=Pragma content=no-cache>
<META Http-equiv=Cache-Control content=no-cache>
<META Http-equiv=Expires content=0>

And 3, the same principle.

7, calculating the time spent implementing

Code began to take time, after taking time subtraction

long t1 = System.currentTimeMillis ();
///////////////// Your code
long t2 = System.currentTimeMillis ();
long time = t2-t1;

8, rounded to retain two decimal places after the decimal point?

import java.text .*;
NumberFormat nf = NumberFormat.getNumberInstance ();
nf.setMaximumFractionDigits (2);
nf.setMinimumFractionDigits (2);
nf.format (numb);
Or (0.005 - 0.01) and then take. After the two

9, form the default method is get.

way is to post high-capacity data transmission server, the method used. (Re-open a socket.?)

10, to prevent users from url directly into the page:

First, add the page to access control. The general use session.

Second, from a web server control and all access to a directory to be verified. (Some say the next jsp into web-inf)

11, the database is a datetime type, insert the current time to the database:

java.sql.Date sqlDate = new java.sql.Date ();
PreparedStatement pstmt = conn.prepareStatement ("insert into foo (time) values (?)");
pstmt.setDate (1, sqlDate);
pstmt.executeUpdate ();

In fact, the general database system has its own function of time.

insert into foo (time) values (sysdate)

12, session access the int type of variable:

session.setAttribute ("int", i +""); / / Note that i + ""
int i = Integer.parseInt (session.getAttribute ("int"));

session some of the concepts.

When users browse the Web, as Http protocol is a stateless protocol, often between different pages of data exchange issues, which requires them to share data between different pages. Common implementation is to save the data to be shared in Session. For example, in the user login page, some users of the information being saved to the Session, and then read the other pages in the user's information. The shared data can be string or primitive data types and Java-related objects, it can be a Java object.

Session can only save the object, can not save the original data type, such as:

session.setAttribute ("count", 10)

Statement is illegal, if we want to save an integer value of 10 Session, the need to use the following method:

session.setAttribute ("count", new Integer (10));

Then in another page using:

(Integer) session.getAttribute ("count")

To read out of this integer.

was set to the session on the system database, but this affected efficiency. session size is best not too

13, the characters into ASCII code

int a = 'A'; out.println (a);

14, String s = new String ("xyz"); created two String Object object, one is "xyx", one is pointing to "xyx" a reference to an object s.

There are typically equals () == this reference with the principles of the stack.

15, swtich no effect on the long on and String:

switch (expr1) in, expr1 is an integer expression. Switch and case statement passed to the parameters should be
int, short, char or byte. long, string can not act on the swtich.

16, Hashtable and HashMap

Dictionary class inherited from Hashtable, the HashMap is the introduction of the Map interface Java1.2 an implementation of HashMap allows null as an entry in the key or value, while Hashtable does not allow the method is Synchronize Hashtable, while HashMap is not, in multiple threads visit Hashtable, the need for its own method of achieving synchronization, and HashMap must be synchronized to provide them things.

  • Some common problems in JSP 2010-07-14

    This article describes a few frequently asked questions articles JSP topics, Hashtable and HashMap, the characters into ASCII code, Session, datetime type, to prevent the user directly input url into the page, form the default method is get, point ba

  • Reactive dyeing solutions to common problems 2010-02-18

    Keywords: reactive dyeing solutions to common problems 1, exhaust dyeing prescription: Configure the exhaust dyeing using reactive dyes prescription must pay attention to what? As the reaction of reactive dyes in different groups, the best dyeing tem

  • Phone recharge common problems and solutions 2010-02-25

    (Only need the password without number) Please call 13800138000 filled according to their own voice prompts This card applies to China Mobile's GSM, Shenzhouxing, mass cards, M-Zone and all other mobile brand users to recharge (Note: in some areas du

  • DB2 UDB Java stored procedures to solve common problems 2010-04-22

    DB2 UDB Java stored procedures to solve common problems Taken from Trusted to run the stored procedure, and because they do not depend on external Java Virtual Machine (Java V

  • ArcGIS Server common problems and solutions 2010-08-30

    ArcGIS Server common problems and solutions Problem Description: After installation is complete, can not open the management page: http://usips:8399/arcgis/manager/ and Service Directory: http://usips:8399/arcgis/rest/ page. Approach: Open the Window

  • HttpClient use some common problems during 2010-12-05

    From: deep in the ship The following describes the process in the use of HttpClient some common problems. Character encoding The encoding of a target page may appear in two places, the first place is the http header returned by the server, and the ot

  • Subversion version control using the common problems and solutions 2011-03-06

    Abstract: Subversion version control using the common problems and solutions. Common Problems and Solutions 1, path, or insufficient permissions error message when prompted: http://localhost (right path) Error * PROPFIND request failed on '/' PROPFIN

  • ORACLE client to connect in server-side Common Problems and Solutions 2011-06-15

    To exclude the client and the server connection problems, first check the client configuration is correct (the client must be configured with the same database server listener configuration), according to error resolved. Here are some common connecti

  • Technical management of several common problems 2010-03-28

    A few days ago to chat with friends, the friend said he had just interviewed from a well-known software company out of my friends went to interview a company's technical management positions, so when the interview questions asked is also emphasis on

  • Apparel direct printing process common problems and their solutions 2010-02-18

    Keywords: clothing direct printing Digital direct printing for apparel produced in the process of deterioration of the quality of the most common factors, the authors put forward here to uphold the highest quality professional solutions:: Clothing di

  • JpGraph learning experience and some common problems 2010-09-13

    Installation JpGraph installation is simple: to download, extract to the application's root path. We use the example of one the Examples directory example0.php example to explain the how the initial use of JpG

  • eclipse under the C / S environment, build common problems 2010-09-15

    I take this platform to speak briefly configuration environment under Eclipse points to note, in most cases, we encountered the largest source of inconsistency is the version of jar package, such as a class I call the method that in fact the old vers

  • Ext summary of common problems 2010-10-30

    scripts/ext/resources/css/ext-all.css//EXT Common CSS, contains all the style ( Must ) scripts/ext/resources/css/icon.css// Custom menu items or other storage page icon scripts/utils/HiTRUST-CMS.css// The old version of the payment system CSS scripts

  • Hadoop common problems and solutions (transfer) 2011-01-26

    1: Shuffle Error: Exceeded MAX_FAILED_UNIQUE_FETCHES; bailing-out Answer: Procedures which need to open multiple files for analysis, the system usually the default number is 1024 (you can see with the ulimit-a) is enough for normal use, but the progr

  • (Switch) Cisco Systems, Inc. VPN use solutions to common problems during 2011-08-31

    A, Error 56: The Cisco Systems, Inc. VPN Service has not been started When using the Cisco vpn, vpn start time, often encountered "Error 56: The Cisco Systems, Inc. VPN Service has not been started" this error. Every time uninstall vpn client re

  • Common problems in all stages of software testing and Solutions Summary 2010-05-07

    1, software test plans and excessive deviation of the actual situation Zai project development in this Wenti software test management is not our individual problems, almost every item of the scheme and the deviation of actual Cunzai, Er Duiyu this is

  • encoding encoding problems two Jsp file 2010-05-08

    5.jsp editing, uploading, compiled into servlet, network transmission what happened? Edit] [jsp file when you save the default windows operating development is in accordance with GBK encoding of the string, you can specify the save as UTF-8 and other

  • SQL Server common problems and solutions 2010-06-04

    Question 1: Use. Net2005 comes with SQL-Express connection is not on. Solution: 1. Network firewall to prevent database connection; 2. Default SQL-Express did not start the Sa account -> download the management studio express interface tools to manag

  • Common problems in network communication 2010-08-01

    1.Ip, port error, port occupied <br /> each computer has a fixed IP, but only IP addresses, can not distinguish between multi-level computer applications, so each server will have a unique port , the value is between the range of integers from 1 to

  • Common Problems in the process of using mysql 2010-10-29

    Mysql database with the process, often need to pay attention to some of the problems recorded in this slightly rearranged in order to prepare for record when the individual. View mysql version in several ways: mysql-V; mysql> status; mysql - help | g