Почему JSON, полученный после страницы формы входа в систему, отображается полноэкранным, а не зарегистрирован в консолиJavascript

Форум по Javascript
Ответить
Anonymous
 Почему JSON, полученный после страницы формы входа в систему, отображается полноэкранным, а не зарегистрирован в консоли

Сообщение Anonymous »

У меня есть веб -приложение, работающее в (встроенный) веб -контейнер для причала 12. Домашняя страница стоит за страницей формы входа. Терминал

[*] surf to http: // localhost: 8080

[*] Войдите в систему с Foo: Bar Credential (Foo Login, Bar Password)

[*]

[*] [*] src/main/java/myservlet.java

[*]src/main/java/webapp.java

[*]src/main/webapp.jed.jed.jed.jed.jed.jesp. />
src/main/webapp/logout.jspобразно /> < /li>
start.sh
< /li>
< /ul>
import java.io.IOException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class EndpointServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.setContentType("application/json; charset=UTF-8");
res.getWriter().append("{ \"key\": 123456789 }");
}
}
< /code>
import java.io.IOException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.getWriter().append("""




const url = "/endpoint";

async function f() {
const response = await fetch(url, { method: "GET" });
const data = await response.json();
console.log(data);
}

setInterval(function() { f() }, 5000); // fetch JSON data from /endpoint every 5s


Hello, web!

""");
}
}
< /code>
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.UserStore;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.util.security.Credential;

public class WebApp {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setWar(args[0]);
HashLoginService loginService =
new HashLoginService("Form-based user authentification realm");
UserStore userStore = new UserStore();
userStore.addUser("foo", Credential.getCredential("bar"), new String[] { "admin" });
loginService.setUserStore(userStore);
server.addBean(loginService);
server.setHandler(context);
server.start();
server.join();
}
}
< /code>
identification.jsp:











< /code>
logout.jsp:

< /code>
web.xml:





LoginServlet
/identification.jsp


LoginServlet
/identification



LogoutServlet
/logout.jsp


LogoutServlet
/logout



MyServlet
MyServlet


MyServlet




EndpointServlet
EndpointServlet


EndpointServlet
/endpoint



Form-based user authentification realm
FORM

/identification




admin




/*


admin




< /code>
pom.xml:


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

4.0.0

testproject
testproject
war
1

Test project
http://localhost/


UTF-8
UTF-8
21
21
12.1.0






org.apache.maven.plugins
maven-compiler-plugin
3.3

UTF-8
256m
2048m

-Xlint:all
-O





org.apache.maven.plugins
maven-war-plugin
3.4.0


WEB-INF/lib/*.jar




org.codehaus.mojo
exec-maven-plugin
3.5.0


run the webapp

java













org.eclipse.jetty
jetty-server
${jetty.version}




org.eclipse.jetty
jetty-security
${jetty.version}




org.eclipse.jetty.ee10
jetty-ee10-apache-jsp
${jetty.version}

nolog




org.eclipse.jetty.ee10
jetty-ee10-annotations
${jetty.version}




org.eclipse.jetty.ee10
jetty-ee10-servlet
${jetty.version}




org.eclipse.jetty.ee10
jetty-ee10-webapp
${jetty.version}





< /code>
start.sh:
#!/bin/bash
mvn exec:java -Dexec.mainClass=WebApp -Dexec.args="target/testproject-1.war"


Подробнее здесь: https://stackoverflow.com/questions/797 ... ad-of-logg
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»