当前位置:网站首页>Using request headers to develop multi terminal applications
Using request headers to develop multi terminal applications
2022-07-05 09:11:00 【The corner of fufu】
servlet page
package com.ssyt.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** * Servlet implementation class UserAgentServlet */
@WebServlet("/ua")
public class UserAgentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/** * @see HttpServlet#HttpServlet() */
public UserAgentServlet() {
super();
// TODO Auto-generated constructor stub
}
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String userAgent = request.getHeader("User-Agent");
response.setContentType("text/html;charest=utf-8");
response.getWriter().println(userAgent);
String output="";
if(userAgent.indexOf("Windows NT")!=-1) {
output = "<h1>This is PC!</h1>";
}else if(userAgent.indexOf("iPhone")!=-1 || userAgent.indexOf("Android")!=-1) {
output = "<h1>This is Mobile!</h1>";
}
response.getWriter().println(output);
}
}
Web effect
PC End
Mobile
边栏推荐
- Confusing basic concepts member variables local variables global variables
- kubeadm系列-02-kubelet的配置和启动
- 2311. 小于等于 K 的最长二进制子序列
- 编辑器-vi、vim的使用
- Composition of applet code
- Ecmascript6 introduction and environment construction
- Generate confrontation network
- Talking about label smoothing technology
- It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
- Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
猜你喜欢
编辑器-vi、vim的使用
Programming implementation of subscriber node of ROS learning 3 subscriber
Solutions of ordinary differential equations (2) examples
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Creation and reference of applet
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
nodejs_ 01_ fs. readFile
Generate confrontation network
L'information et l'entropie, tout ce que vous voulez savoir est ici.
Applet data attribute method
随机推荐
Rebuild my 3D world [open source] [serialization-1]
2311. 小于等于 K 的最长二进制子序列
Nodejs modularization
交通运输部、教育部:广泛开展水上交通安全宣传和防溺水安全提醒
File server migration scheme of a company
fs. Path module
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
MPSoC QSPI flash upgrade method
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
[code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
Blogger article navigation (classified, real-time update, permanent top)
Hosting environment API
Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
Codeforces Round #648 (Div. 2) D. Solve The Maze
Programming implementation of subscriber node of ROS learning 3 subscriber
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Shutter uses overlay to realize global pop-up
Programming implementation of ROS learning 2 publisher node
3D reconstruction open source code summary [keep updated]
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet