Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[JSP] Quasiäquivalent zu globalen Variablen in PHP (IP-Adresse und localhosi)

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

in PHP kenne ich mich aus, in JSP so gut wie überhaupt nicht. Aber ich soll auch nur eine kleine Sache in eine laufende Anwendung einbauen und zwar:

Soll die Login Prozedur übersprungen werden, sofern der "Surfer/Besucher" der Seite, der Rechner selbst, sprich der localhost ist. Letztendlich eine einfache Erweiterung eine if-Verzweigung. Nur wie realisiere ich das in JSP? In Pros brächte ich quasi:

Wenn Surfer.IP = Localhost.IP dann lass es ...

Das sollte für jemanden der erfahren darin ist doch ein Kinderspiel sein mir dort zu helfen :hells:

Du kommst innerhalb eines JSP Blocks an das aktuelle HttpServletRequest Objekt. Darüber erhälst du alle Infos, die der User geschickt hast.

Die zwei Properties heisstn remoteHost und remoteAddr

An in etwa so:


<%


  String remoteHost    = request.getRemoteHost();

  String remoteIP      = request.getRemoteAddr();

  if(remoteHost.equalsIgnoreCase("localhost") || remoteIP.equalsIgnoreCase("127.0.0.1")) {


    // Client kommt von lokaler Machine also nix machen


  } else {


    // Client kommt von remote Machine also login

    performLogin();


  }


%>

Etwas ausführlicher, wenn du wirklich auf die eigene IP vergleichen willst:

<%


  String remoteHost    = request.getRemoteHost();

  String remoteIP      = request.getRemoteAddr();

  String localHost     = InetAddress.getLocalHost().getHostName();

  String localIP       = InetAddress.getLocalHost().getHostIP();


  if(remoteHost.equalsIgnoreCase(localHost) || remoteIP.equalsIgnoreCase(localIP)) {


    // Client kommt von lokaler Machine also nix machen


  } else {


    // Client kommt von remote Machine also login

    performLogin();


  }


%>

Hm,

sprich jeder der Shellzugriff hat, kann mit der Anwendung ohne Login arbeiten, ist das gewünscht?

Oder brauchst du nur eine Methode um dich beim testen nicht immer anmelden zu müssen?

Gruß Jaraz

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.