Use JSP to write a character statistics program that requires users to enter strings for statistics

WBOY
Release: 2024-01-22 14:54:16
forward
1233 people have browsed it

Use JSP to write a character statistics program that requires users to enter strings for statistics

Write a word count program using JSP language. The program requires the user to input string statistics

I used regular expressions to help you get it:

Required package: java.util.regex.Pattern;

String str=request.getParameter("str"); //Get the value of that text box, assuming it is str

int numberCount=0; //Number of numbers

int aplha=0; //number of letters

int other=0; //Other number

for(int i=0;i

if(Pattern.matches("^[0-9]",str.charAt(i) "")){

numberCount ;

}

else if(Pattern.matches("^[a-z]||[A-Z]",str.charAt(i) "")){

aplha ;

}

else{

other ;

}

response.getWriter.println("number:" numberCount "letter:" aplha "other:" other)

}

Write guessing numbers in jsp

Because there is no control named num defined on your index.jsp page, so request.getParameter("num") is NULL.

Change on the index.jsp page to , that is, name=num"changed to name="num"(num is preceded by double quotes), value=""changed to value=""( Just remove the spaces between the double quotes).

The complete index.jsp file content is as follows: (guess.jsp file does not need to be modified)

Please enter a number from 1-100:

Please write a JSP page, enter a number into the JSP page, click the button to submit the page

Input interface:

Demo
Please enter a number:

Processing, output interface:

You entered an even number

You entered an odd number

## JSP text input number problem

It’s very simple with javascript

Add

in the middle

<script><p> function test(){<p> var obj = document.getElementById("id").value; // Replace the id here with your own text id<p> if(obj>0 && obj<100){<p> return true;<p> }else<p> alert("cuowu");<p> }<p> </script>

In your submit button action="test(); return false;"

Written directly here without testing

You can learn javascript yourself, it’s a very simple thing

The above is the detailed content of Use JSP to write a character statistics program that requires users to enter strings for statistics. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!