簡體   English   中英

我想在任何 javascript 或 servlet 的幫助下使用 html 文本框從文本文件中讀取和替換字符串?

[英]I want to read and replace string from text file using html textboxes with the help of any javascript or servlet?

<doctype!>
<html>
     <head>
        <title>prashant</title> 
        <style>
            body{
                background: #ffffcc
            }
            form{
                weidth:200px;
                padding:20px;
                margin:auto;
                font-size: 20px;
                align-items: stretch;
                position: inherit;
                border: 1px white solid;
                border-radius: 10px;
            }
            input[type=text]{
                weidth:100;
                padding:5px;
                font-size:17px;
                margin:  20px;
                position:relative;
            }
            input[type=submit]{
                padding: 5px;
                font-size:18px;
                position: relative;
            }
            h3{
               text-align: center;
               font-size: 40px;
            }
          </style> 
       </head>
    <body bgcolor="white">
        <font size="20">
    </font>
    <h3><mark><strong>barcode printing</strong></mark></h3>
            <center>
                <form name="form1" action="./NewServlet" method="modifyFile">
                  
        WARE HOUSE<input type ="text" id="fname"><br>
        ITEM NAME <input type ="text" id="iname"><br>
        SERIAL NO. <input type ="text" name="serial"><br>
    <input type="hidden" form="file" value="38x25prn.txt">
   GROUP<input type ="text" name="group"><br>
        ASP<input type ="text" name="asp"><br>
        <input type="submit" value="print" onclick="loadFileAsText()">  <input type ="submit" value ="close" onclick="close()">
      </form>
</center>
  
 
     </body>
    </html>

這是代碼,請在讀取文件並替換文本文件中的字符串時執行此操作。 我想通過使用 servlet 或 java 腳本來替換文本文件中的字符串。 首先,我有一個 html 頁面,由文本框和按鈕組成,如果我在該文本框中寫一些東西並按下按鈕,那么它應該必須在我的計算機中讀取一個文本文件並從我寫的那個字符串中替換一個特定的字符串文本框。

不過最好使用servlet,至少我是這樣認為的。 你可以這樣做。

在 jsp 頁面:

 <form action="blah" method="POST"> <input type="text" name="textr"> <input type="text" name="textn"> <input type="submit" value="whatever you want here"> </form>

在 servlet doPost() 方法中:

 String str=request.getParameter("textr"); String stn=request.getParameter("textn"); String filePath = "Path here"; Scanner sc = new Scanner(new File(filePath)); StringBuffer buffer = new StringBuffer(); while (sc.hasNextLine()) { buffer.append(sc.nextLine()+System.lineSeparator()); } fileContents = fileContents.replaceAll(textr, stn);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM