Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that if is judged to be NULL after the value of request.getParameter

2025-03-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to solve the problem that if is judged as NULL after the value of request.getParameter", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to solve the problem of judging if as NULL after request.getParameter value".

After taking the value of request.getParameter, if is judged to be NULL

The following is part of my program. The Auto_space_time_ok.jsp file obtains the value code from Auto_space_time.jsp. Here the blogger needs to make a judgment that when danwei equals the "school" string, assign the value of zhuangtai to zhengzhuang.

At the beginning, use the statement to determine if (danwei = "school") zhengzhuang = zhuangtai

As a result, no value is obtained, and the output statement is null.

System.out.print (zhengzhuang)

Change the judgment statement to

If ("school" .equals (danwei)) zhengzhuang = zhuangtai

To solve the problem.

Find out the cause

What we are comparing here is the numerical value, the basic data type, that is, the original data type. Byte,short,char,int,long,float,double,boolean, when comparing values between them, can be used directly (= =), while as String,Integer,Date these complex data types (classes), compare values with .equals, and at this time (= =) compare addresses.

Several possibilities for request.getParameter to get null in servlet

This article aims at the situation that servlet gets null after form form is submitted in jsp.

Possibility one

The name attribute value is not set in the input tag that needs to be entered in jsp

Correct for example:

Because after the form is submitted, if you want to use request.Parameter () in servlet to get the value, it is matched with the value of name in input instead of id.

Value is fine with or without it.

Possibility two

The action attribute in form is not consistent with the name in Webservlet

Possibility three

The form form should be submitted as post instead of get (the value of the method attribute)

Correct for example:

Typically exists in the first few lines of the servlet file:

@ WebServlet ("/ Modify") possibility 4

Responsible for the problem of the button submitted by the form

As we all know, when you need to submit a form, you also need a "button".

There may be people who don't need buttons, but what I've written so far is probably needed.

When you can't use input's submit submit button but something else, such as a hyperlink, if you write the same content in the hyperlink's href as in form's action, congratulations, you'll probably get a null.

Like this:

In fact, this is also the problem I encountered, and this is how I solved it.

Function modify () {document.getElementById ("modifyForm") .submit ();

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report