更新时间:2023-12-04 17:49:17
在context.xml中
In context.xml
<context antijarlocking="true" path="/myDBname" allowcasualmultipartparsing="true">
<realm classname="org.apache.catalina.realm.CombinedRealm">
<realm classname="org.apache.catalina.realm.JDBCRealm" drivername="com.mysql.jdbc.Driver">
name="myDBname" type="javax.sql.DataSource"
connectionURL="jdbc:mysql://localhost:3306/mydbname"
connectionName="root" connectionPassword="sasa"
userTable="administrators" userNameCol="Email" userCredCol="Password"
userRoleTable="administrators" roleNameCol="LoginRole"
auth="Container" maxTotal="100" maxIdle="30" maxWaitMillis="10000"/>
</realm>
</realm></context>
web.xml
web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>myDBname</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>myDBname</realm-name>
<form-login-config>
<form-login-page>/pages/Login.jsp</form-login-page>
<form-error-page>/pages/Error.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrator</description>
<role-name>admin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>myDBname</web-resource-name>
<url-pattern>/pages/admin/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<welcome-file-list>
<welcome-file>pages/home.jsp</welcome-file>
</welcome-file-list>
Copied mysql-connector-java-5.1.23-bin.jar into C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.15\lib
I also use <%= request.getContextPath() %> in order to connect resources to pages
Copied mysql-connector-java-5.1.23-bin.jar into C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.15\lib
I also use <%= request.getContextPath() %> in order to connect resources to pages
<link href="<%= request.getContextPath() %>/resources/styles/main.css" rel="stylesheet" type="text/css" />