Witam. To jest kod w JSP:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="pl.Szyszka.Main" %>
<!DOCTYPE html>
<html lang="pl">
<head>
<link href=https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap rel="stylesheet">
<link type="text/css" rel="stylesheet" href=css/style.css>
<title>WebApp1</title>
</head>
<body>
<%=Main.getAndSaveLogin()%>
<script src="js/script.js"></script>
<center><input type="text" id="loginField" value="Nazwa użytkownika"></center>
<center><input type="submit" id="register" value="Zarejestruj"></center>
</body>
</html>
A to w Javie:
package pl.Szyszka;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
public static String getAndSaveLogin() throws FileNotFoundException {
File file = new File("db.txt");
Scanner scanner = new Scanner(file);
String line = scanner.nextLine();
return line;
}
}
Gdy próbuję wejść na stronę, pojawia się coś takiego: https://imgur.com/a/CnT3hbC
Dlaczego? Jak mam inaczej odczytać tekst z pliku txt? W Java SE wszystko działa po zamianie "return line" na "System.out.println(line)"