当前位置:网站首页>利用请求头开发多端应用
利用请求头开发多端应用
2022-07-05 09:03:00 【緈福的街口】
servlet页面
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);
}
}
网页效果
PC端
移动端
边栏推荐
- Count of C # LINQ source code analysis
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
- Return of missing persons
- uni-app 实现全局变量
- 3D reconstruction open source code summary [keep updated]
- Characteristic Engineering
- Confusion matrix
- C#绘制带控制点的Bezier曲线,用于点阵图像及矢量图形
- 优先级队列(堆)
- Blue Bridge Cup provincial match simulation question 9 (MST)
猜你喜欢
RT-Thread内核快速入门,内核实现与应用开发学习随笔记
Halcon clolor_ pieces. Hedv: classifier_ Color recognition
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Applet (subcontracting)
Solutions of ordinary differential equations (2) examples
Huber Loss
C [essential skills] use of configurationmanager class (use of file app.config)
Attention is all you need
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
随机推荐
Generate confrontation network
Meta tag details
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
Solutions of ordinary differential equations (2) examples
How many checks does kubedm series-01-preflight have
驾驶证体检医院(114---2 挂对应的医院司机体检)
[daiy4] copy of JZ35 complex linked list
Programming implementation of subscriber node of ROS learning 3 subscriber
ROS learning 1- create workspaces and function packs
Programming implementation of ROS learning 2 publisher node
Nodejs modularization
uni-app 实现全局变量
12. Dynamic link library, DLL
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
Halcon wood texture recognition
特征工程
Blogger article navigation (classified, real-time update, permanent top)
kubeadm系列-01-preflight究竟有多少check
深度学习模型与湿实验的结合,有望用于代谢通量分析
Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning