📄 simplewtcservlet.java
字号:
package wlsunleashed.wtc;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import wlsunleashed.wtc.Account;
public class SimpleWTCServlet extends HttpServlet {
private String defaultString = "20004";
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException {
String convertedString, inputString;
//read the request parameter INPUT_STRING
// If the input String is null
// it returns "hello world" In uppercase
if ((inputString = req.getParameter("ACCOUNT_ID")) != null) {
convertedString = inputString.toUpperCase();
} else {
convertedString = defaultString;
}
String bal ="";
Account acct = new Account();
acct.setId(Integer.parseInt(convertedString));
try {
bal = acct.getBalance();
} catch ( Exception e) {
e.printStackTrace();
}
// Set the content type first
res.setContentType("text/html");
// get the PrintWriter
PrintWriter out = res.getWriter();
out.println("<html><head><title>SimpleWTCServlet</title></head>");
out.println("<body>");
out.println("<h1>");
out.println(" Account Balance for ("+convertedString+")="+ bal);
out.println("</h1></body></html>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -