顯示具有 Servlet 標籤的文章。 顯示所有文章
顯示具有 Servlet 標籤的文章。 顯示所有文章

2021年3月2日 星期二

Cookie的setHttpOnly()和setSecure()

https://openhome.cc/Gossip/ServletJSP/Cookie.html

https://ajoshow.com/2017/07/19/201707192223/

 

Spring設定
https://www.itread01.com/content/1558404302.html
public class MainWebAppInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext sc) throws ServletException {
        sc.getSessionCookieConfig().setHttpOnly(true);        
        sc.getSessionCookieConfig().setSecure(true);        
    }
}

2021年3月1日 星期一

JSR 315: Java Servlet 3.0 Specification

https://jcp.org/en/jsr/detail?id=315

https://openhome.cc/Gossip/ServletJSP/Configuration.html

https://zhuanlan.zhihu.com/p/81885441

使用Spring Boot免去web.xml

使用Spring Boot进行Web开发的时候,按照官方的推荐都是使用内嵌的Servlet容器,和应用一起打包成jar包部署,当然,我们可以使用传统war包来部署,Main Class只需继承org.springframework.boot.web.servlet.support.SpringBootServletInitializer即可(启动时会加载所有ServletContainerlnitializer)。

免去web.xml是通过Servlet 3.0中的javax.servlet.ServletContainerInitializer来实现的,ServletContainerInitializer是提供了一个实现和web.xml类似功能的接口,在应用启动的时候能够通过编程的方式来注册Servlet、Fileter、Listener的功能。

SpringBoot通过Servlet3.0的这个设计,结合SPI机制,在spring-web包下发现META-INF/services/javax.servlet.ServletContainerInitializer实现类:org.springframework.web.SpringServletContainerInitializer从而进行初始化,包括对DispatcherServlet的注册,ContextLoaderListener的注册等等,最终免去web.xml


2020年11月22日 星期日

Servlet輸出中文有問號???

已經確認資料來源編碼沒問題,log也可以正常顯示中文字
但Servlet頁面一直顯示問號???

解決方式:
需在response.getWriter()的之前加入以下設定
response.setContentType("text/html;charset=UTF-8");
如果使用Big5加入
response.setContentType("text/html;charset=Big5");