simplewtcservlet.java

来自「BEA WebLogic Server 8.1大全 = BEA webLogic」· Java 代码 · 共 53 行

JAVA
53
字号
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 + =
减小字号Ctrl + -
显示快捷键?