| |

VerySource

 Forgot password?
 Register
Search
View: 930|Reply: 4

request initialization problem

[Copy link]

3

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-18 14:20:01
| Show all posts |Read mode
HttpServletRequest request = null;
request.setCharacterEncoding ("GB2312");
HttpSession session = request.getSession ();
-------------------------
Error reported: java.lang.NullPointerException
-------------------------
How is request initialized not null?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-24 18:54:02
| Show all posts
Your code should be written in the servlet's doGet () or doPost () method. The request is instantiated by the servlet container. You only need to use it and do not require our programmer to initialize it. Please remove your HttpServletRequest request = null;
If you can use it directly in jsp. request is an implicit object of jsp.
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-25 23:00:01
| Show all posts
request is one of the implicit objects of jsp, no initialization required
Reply

Use magic Report

2

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Invalid IP Address

Post time: 2020-1-30 12:00:01
| Show all posts
I wonder if your request is used in doGet, doPost and other methods or DAO for general data operations? If it is in the doGet and doPost methods, this kind of exception does not usually occur. If it is in DAO, declare it in the parameter line of the function.
such as
public void myMethod (HttpServletRequest request) {
   // do somethings
}
Then in and out of the servlet or Aciton, the object of the HttpservletRequest declared in the function header can be used. It should not be wrong.
Reply

Use magic Report

3

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-31 05:54:02
| Show all posts
Then I will call myMethod, and pass parameters to him. What is it?
What I did was a single class, which took out the contents of the database and put it in the session, without using the servlet's doGet, doPost and other methods.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list