当前位置 : 主页 > 编程语言 > java >

JSP/Servlet初识一

来源:互联网 收集:自由互联 发布时间:2021-06-25
Servlet简介 Servlet是一个运行在服务器端的小程序,这个小程序负责动态的解析网页成html格式,她是一种Web服务器,也是一个容器 JSP(JAVA Server Page)是一种特殊的Servlet Tomcat安装启动 下载

Servlet简介

Servlet是一个运行在服务器端的小程序,这个小程序负责动态的解析网页成html格式,她是一种Web服务器,也是一个容器


JSP(JAVA Server Page)是一种特殊的Servlet


Tomcat安装启动

下载 Tomcat后解压,打开DOS窗口后,进入Tomcat的bin目录下,运行startup启动tomcat,运行shutdown关闭tomcat

但是其实都是调用的catelina这个脚本来执行的,所以可以直接运行catalina start来启动tomcat,catalina stop关闭tomcat


启动错误怎么办?

当你启动的时候如果出现错误,会一闪而过,这时候想要查看错误信息和困难,这时候可以用debug的方式来运行

catalina debug然后敲入run来以debug的方式来运行,然后可以查看错误信息


Tomcat目录结构

bin 二进制可执行文件和脚本

conf 配置文件目录

logs 日志文件目录

lib catalina本身和web应用可加载的类的目录

server 服务器所需的类库目录

shared webapp共享的目录

webapps web应用所存放的目录

work tomcat的工作目录

temp 存放临时文件的目录



Tomcat的配置文件

conf/server.xml

服务器的主配置文件

在这个配置文件里面搜索8080,可以更改端口

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />





conf/web.xml

定义所有web应用的配置

缺省的Servlet定义和MIME类型定义

conf/tomcat-user.xml

定义了tomcat用户的信息,安全权限相关




进入webapp管理界面时,一般会有403错误

403 Access Denied

You are not authorized to view this page.

By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.

If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.

If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.

manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only
The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.
For more information - please see the Manager App HOW-TO.


原来是没有用户认证,但是在我看视频的时候,他们用的是添加一个用户角色叫manager,把要登陆的用户加入到角色中,但是我尝试的时候是不可行的,原来manager被换成了四种角色,名字变了,分工更为明确,具体可以看我上面贴的英语,这里不再解释



  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager-gui"/>
  
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/> 


  <user username="tomcat" password="tomcat" roles="tomcat,manager-gui,manager-jmx,manager-status"/>
  <user username="both" password="both" roles="tomcat,role1"/>
  <user username="role1" password="role1" roles="role1"/>

但是注意一点

角色

manager-gui

不能和

角色

manager-script or manager-jmx
 

同时赋予给一个用户

网友评论