(property) Document.title: string document.title
时间: 2024-03-08 18:48:18 浏览: 13
是一个字符串类型的属性,表示当前文档的标题。可以通过document.title来获取或设置当前文档的标题。例如,如果当前文档的标题是"Hello World",可以通过以下代码来获取或修改它:
获取标题:
```javascript
var title = document.title;
console.log(title); // 输出:Hello World
```
修改标题:
```javascript
document.title = "New Title";
console.log(document.title); // 输出:New Title
```
相关问题
shiro ajax登录的简单例子,要包括.xml文件
以下是基于 Shiro 的 Ajax 登录的简单示例,包括.xml文件:
1. 创建一个login.html页面,包括一个表单和jQuery代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<h2>Login</h2>
<form id="loginForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br>
<input type="submit" value="Login">
</form>
<div id="message"></div>
<script>
$(document).ready(function() {
$('#loginForm').submit(function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: 'login',
data: $(this).serialize(),
success: function(data) {
if (data.success) {
window.location.href = 'index.html';
} else {
$('#message').text(data.message);
}
}
});
});
});
</script>
</body>
</html>
```
2. 创建一个Controller类,处理登录请求,返回JSON数据:
```java
@Controller
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> login(HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> result = new HashMap<>();
String username = request.getParameter("username");
String password = request.getParameter("password");
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
try {
SecurityUtils.getSubject().login(token);
result.put("success", true);
} catch (UnknownAccountException e) {
result.put("success", false);
result.put("message", "Unknown account");
} catch (IncorrectCredentialsException e) {
result.put("success", false);
result.put("message", "Incorrect password");
} catch (LockedAccountException e) {
result.put("success", false);
result.put("message", "Account is locked");
} catch (AuthenticationException e) {
result.put("success", false);
result.put("message", "Authentication failed");
}
return result;
}
}
```
3. 配置Shiro的.xml文件,包括Shiro的过滤器和Realm:
```xml
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login.html"/>
<property name="successUrl" value="/index.html"/>
<property name="unauthorizedUrl" value="/unauthorized.html"/>
<property name="filterChainDefinitions">
<value>
/login = anon
/logout = logout
/static/** = anon
/** = authc
</value>
</property>
</bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="myRealm"/>
</bean>
<bean id="myRealm" class="com.example.MyRealm">
<property name="credentialsMatcher" ref="hashedCredentialsMatcher"/>
</bean>
<bean id="hashedCredentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<property name="hashAlgorithmName" value="SHA-256"/>
<property name="hashIterations" value="1000"/>
</bean>
```
4. 创建一个Realm类,实现Shiro的认证和授权方法:
```java
public class MyRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// TODO: 实现授权方法
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken userToken = (UsernamePasswordToken) token;
String username = userToken.getUsername();
User user = userService.getUserByUsername(username);
if (user == null) {
throw new UnknownAccountException();
}
return new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName());
}
}
```
以上是一个基于 Shiro 的 Ajax 登录的简单示例,可以参考实现自己的功能。
授权委托书 (模板) 委托人:_____________,公民身份号码:________________, 受托人:_____________,公民身份号码:________________, 委托人婚烟声明,个人所有或与X共有大连市行政地址号房产,此房无其他共有人。现欲办理该房产业务类型,因事由无法前往大连市不动产登记中心,特委托_________(受托人何种关系)为代理人,委托事项具体如下: 1、(选择)委托事项; ...................... 2、(必要)接受询问、代为承诺;提交登记申请和资料、代为在相关登记文书上签字,按手印。 受托人在上述权限内承办的一切事务及签署的相关文件委托人均认可,并承担相应法律责任。委托期限:七天。 委托人: 受托人: 年 月 日 ,用itext编写java程序
以下是使用 iText 编写的 Java 程序,用于生成授权委托书模板:
```java
import java.io.FileOutputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
public class AuthorizationLetterTemplate {
public static void main(String[] args) {
try {
// 创建 PDF 文档对象
Document document = new Document();
// 创建 PDF 输出流
PdfWriter.getInstance(document, new FileOutputStream("AuthorizationLetter.pdf"));
// 打开 PDF 文档
document.open();
// 设置字体
BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font font = new Font(baseFont, 12, Font.NORMAL);
// 添加标题
Paragraph title = new Paragraph("授权委托书", new Font(baseFont, 16, Font.BOLD));
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
// 添加委托人信息
Paragraph grantor = new Paragraph("委托人:_____________,公民身份号码:________________,", font);
document.add(grantor);
// 添加受托人信息
Paragraph trustee = new Paragraph("受托人:_____________,公民身份号码:________________,", font);
document.add(trustee);
// 添加房产信息
Paragraph property = new Paragraph("委托人声明,个人所有或与X共有大连市行政地址号房产,此房无其他共有人。", font);
document.add(property);
// 添加委托事项
Paragraph item = new Paragraph("委托事项:", font);
document.add(item);
// 添加选择项
Paragraph selection = new Paragraph("(选择)委托事项; ......................", font);
document.add(selection);
// 添加必要项
Paragraph necessary = new Paragraph("(必要)接受询问、代为承诺;提交登记申请和资料、代为在相关登记文书上签字,按手印。", font);
document.add(necessary);
// 添加委托期限
LocalDate date = LocalDate.now().plusDays(7);
Paragraph deadline = new Paragraph(String.format("委托期限:%s。", date.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))), font);
document.add(deadline);
// 添加签名
Paragraph signature = new Paragraph("委托人: 受托人: ", font);
signature.setAlignment(Element.ALIGN_RIGHT);
document.add(signature);
// 关闭 PDF 文档
document.close();
System.out.println("授权委托书生成成功!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
该程序会生成一个名为 `AuthorizationLetter.pdf` 的 PDF 文件,其中包含授权委托书的模板。你可以根据需要修改程序中的文字内容、字体样式、文件名等参数。