JAVA毕业作业,做一个小程序,要求实现以下功能,请各路大神帮忙啊。。含泪跪求答案。0.0

JAVA毕业作业,做一个小程序,要求实现以下功能,请各路大神帮忙啊。。含泪跪求答案。0.0,第1张

web工程:

1、sevlet文薯亏件:

package com.fylsh

import java.io.FileNotFoundException

import java.io.FileOutputStream

import java.io.IOException

import java.io.PrintWriter

import javax.servlet.ServletException

import javax.servlet.http.HttpServlet

import javax.servlet.http.HttpServletRequest

import javax.servlet.http.HttpServletResponse

public class Servlet1 extends HttpServlet {

private static final long serialVersionUID = -1728620555703188993L

public Servlet1() {

}

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

this.doPost(req, resp)

}

protected void doPost(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

req.setCharacterEncoding("utf-8")

resp.setCharacterEncoding("utf-8")

String num1=req.getParameter("神知number1")

String num2=req.getParameter("number2")

String num3=req.getParameter("number3")

String num4=req.getParameter("number4")

String num5=req.getParameter("number5")

req.setAttribute("maxPrime", getPrimeNumber(Integer.parseInt(num3)))

writeToFile(num1+" "+num2+" "+num3+" "+num4+" "+num5,req.getRealPath("")+"/numberFile.txt")

req.getRequestDispatcher("index.jsp").forward(req,resp)

}

public void writeToFile(String res,String path){

try {

PrintWriter pw=new PrintWriter(new FileOutputStream(path,true))

pw.println(res)

pw.close()

} catch (FileNotFoundException e) {

e.printStackTrace()

}

}

public int getPrimeNumber(int input){

if(input<=0)return -1

int MAXINT=Integer.MAX_VALUE

while(true){

input++

if(isPrime(input))

return input

if(input>MAXINT-1)

return -1

}

}

public boolean isPrime(int input){

for(int i=2i<input/2+1i++){

if(input%i==0)return false

}

return true

}

}

2、web.xml配置:

<?xml version="1.0" encoding="UTF-8"数瞎神?>

<web-app version="2.5"

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>

<servlet-name>Servlet1</servlet-name>

<servlet-class>com.fylsh.Servlet1</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Servlet1</servlet-name>

<url-pattern>/servlet1</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

3、\web\index.jsp文件内容:

<%@ page language="java" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>My JSP 'index.jsp' starting page</title>

</head>

<body style="font-size: 14px">

<h3>请在下面输入框中输入整数</h3>

<form action="servlet1" method="post">

整数1:<input type="text" name="number1"/><br/>

整数2:<input type="text" name="number2"/><br/>

整数3:<input type="text" name="number3"/><br/>

整数4:<input type="text" name="number4"/><br/>

整数5:<input type="text" name="number5"/>

<input type="submit" value="提交">

</form>

<%if(request.getAttribute("maxPrime")!=null){

%>

大于整数3的最小素数为:<%=request.getAttribute("maxPrime") %>

<%

} %>

</body>

</html>

if rv is not None and rsv is not None:

# extract version/subversion

self._nmap_version_number = int(line[rv.start():rv.end()])

self._nmap_subversion_number = int(line[rsv.start()+1:rsv.end()])

break

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12310463.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存