使用httpservlet測試類測試interface
阿新 • • 發佈:2019-02-11
<servlet>
<description>我的測試</description>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.hand.ws.servlet.TestOtmOutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/ws/test</url-pattern>
</servlet-mapping>
2、 在對應路徑開發程式碼
//自行引包
public class TestServlet extends HttpServlet{
@Autowired
private TestService testService;
public void init(ServletConfig config) throws ServletException {
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
config.getServletContext());
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
try {
//設定傳值
//呼叫方法
testService.test()';
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}