在netbeans中创建一个web服务器与我有3个文件index.jsp,response.jsp和client.java。 的想法是创建一个温度转换器,但只需要输入,而不是做计算器的工作。 请任何帮助!?java类调用/调用jsp文件
的index.jsp
<form name="Input Form" id="ftemp" action="response.jsp">
<input type="text" name="temp" />
<select name="conv1">
<option>Celsius</option>
<option>Fahrenheit</option>
</select>
<select name="conv2">
<option>Fahrenheit</option>
<option>Celsius</option>
</select>
<input type="submit" value="Submit" />
</form>
的response.jsp
<body>
<h1>your list is in order</h1>
<jsp:useBean id="sortbean" scope="session" class="sortclient.SortClient" />
<jsp:setProperty name="sortbean" property="input" />
<jsp:setProperty name="sortbean" property="cel" />
<jsp:setProperty name="sortbean" property="fahr" />
<jsp:getProperty name="sortbean" property="input" />
</body>
client.java
public class SortClient {
private String input;
double cel = 0;
double fahr = 0;
public SortClient(){
input = null;
}
public String getInput() {
try{
String key = getKey();
input = mergeSort (input,key);
double tempCelsius = input.nextDouble();
double tempFahrenheit = input.nextDouble();
return input;
}catch (Exception ex){
System.out.println(ex); //we would log this
return "That is not a valid list";
}
}
public void setInput(String input) {
this.input = input;
}
public double toCelsius(double tempFahrenheit)
{
return ((5.0/9.0) * (tempFahrenheit - 32));
}
public double toFahrenheit(double tempCelsius)
{
return (tempCelsius * 9.0/5.0) + 32;
}
private static String mergeSort(java.lang.String input, java.lang.String userKey) {
org.tempuri.Service service = new org.tempuri.Service();
org.tempuri.IService port = service.getBasicHttpBindingIService();
return port.mergeSort(input, userKey);
}
private static String getKey() {
org.tempuri.Service service = new org.tempuri.Service();
org.tempuri.IService port = service.getBasicHttpBindingIService();
return port.getKey();
}
您需要将请求转发到从JSP模型的逻辑,再往前一个响应页面。查看“模型 - 视图 - 控制器”(MVC),特别是旧的“模型2”架构。一分钟或三次搜索后,我发现这些链接: https://en.wikipedia.org/wiki/JSP_model_2_architecture http://www.javaworld.com/article/2076557/java-web-development/understanding-javaserver -pages-model-2-architecture.html –