开发者

How to display Operating System information in JSP?

开发者 https://www.devze.com 2023-01-24 08:52 出处:网络
i want my jsp page to display the operating system information to the user开发者_如何学Python. Server side OS information

i want my jsp page to display the operating system information to the user开发者_如何学Python.


Server side OS information
JSP which is java can find the OS of the computer where it is executing. we can use the getProperty() method to find the System properties of the system. It returns a String with the name of OS. It supports various OSs in java.

Example:

<%@ page language="java"%>
<html>
<head>
<title>Example for Printing the OS name</title>
</head>

<body>
<%
 out.println("OS: " + System.getProperty("os.name"));
%>
</body>
</html>

Client side information

String agent = request.getHeader ("user-agent");
StringTokenizer st = new StringTokenizer (agent ,";");
st.nextToken ();

// Get the user's browser name
String userBrowser = st.nextToken ();

// Get the user's operating system name
String userOs = st.nextToken ();


Your best bet is user agent sniffing. It's available by request.getHeader("user-agent"). There's even a 3rd party webservice to which you can submit this string and obtain detailed information: http://user-agent-string.info

Another way is using a Java applet and gather the information by System.getProperty("os.name"). This is a bit more reliable since the user agent can be spoofed by the client.


You can use script to get the PC info, such as:

<script>
    document.write(navigator.userAgent + "<br />");
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消