更新: GotApp.javaを追加するのを忘れていました
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GotApp extends HttpServlet {
static DatabaseConn connection = null;
static UserStore dataStore = null;
static TaskCoderWtc coder = null;
ServletContext servletContext = null;
static String coderApp = null;
static String workDir = null;
public void init() {
try {
servletContext = getServletContext();
coderApp = getParameter("tricon.proxy"); //exists in web.xml
workDir = getParameter("data.dir"); //exists in web.xml
dataStore = new UserStore(workDir); //exists in web.xml
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
doPost(req, resp);
}
public UserStore getDataStore() {
return dataStore;
}
public DatabaseConn getConnection() { // FIXME This needs a better name.
return connection;
}
String getParameter(String str) throws Exception {
if (servletContext == null) {
throw new Exception("servletContext is null.");
return servletContext.getInitParameter(str);
}
public User getUser(HttpServletRequest req, HttpServletResponse resp)
throws ServletException {
// We only really need req.
return dataStore.loadUser(getUsername(req));
}
// Will never return null.
public Task getTask(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
User user = getUser(req, resp);
//if (user == null) {
// return null;
//}
String taskname = req.getParameter("taskname");
Task task = new Task(taskname);
// Make a quick check here.
if (task.isCoding()) {
resp.sendRedirect("task.jsp?" + req.getQueryString());
}
user.addTask(task);
return task;
}
public String getAction(HttpServletRequest req) {
String action = req.getParameter("action");
if (action == null) {
action = "";
}
return action.toLowerCase();
}
ユーザーに4つのオプションを選択するように求めるWebページがあり、選択に応じて文字列として保存されます。これは私のhtmltask.javaにあります:
import com.nav.wtc.model.coder.TaskRunner;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import helper.DatabaseConn;
import helper.UserStore;
import pages.GotApp;
public class HtmlTask extends GotApp {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
super.doPost(req, resp);
UserStore dataStore = getDataStore();
DatabaseConn connection = getConnection();
TaskRunner runner = getTaskRunner();
Task task = getTask(req, resp);
String action = getAction(req);
resp.getWriter().println(showPage(task));
}
public String showPage(Task task) {
StringBufn sb = new StringBufn();
sb.add("<html>");
sb.add("<body>");
sb.add(showCall(task));
sb.add("</body>
sb.add("</html>
return sb.toString();
}
private String showCall(Task task) {
StringBufn sb = new StringBufn();
sb.add("<div class='area'>");
sb.add("<form method='get' action='task.jsp'>");
sb.add(" <table>");
sb.add(" <tr class='1'>");
sb.add(" <td>");
sb.add(" What level would you like to code to: <br> ");
sb.add(" <input type ='radio' name='call' value='valsel'> Selections<br> ");
sb.add(" <input type ='radio' name='call' value='valselpbd'> Parts<br> ");
sb.add(" <input type ='radio' name='call' value='valselhbd'> Holes<br> ");
sb.add(" <input type ='radio' name='call' value='valselrbd'> C-BOMs<br> ");
sb.add(" <input type ='radio' name='call' value='valselpbdrbd'> BOMs<br> ");
sb.add(" <input type='submit' value='Run Task' />");
sb.add(" </td>");
sb.add(" </tr>");
sb.add(" </table>");
sb.add("</form>");
sb.add("</div>");
return sb.toString();
}
ここで値の 1 つ (ユーザーによって送信される) を取得し、それをTaskCoderImpl.javaという別の Java クラス ファイルの入力として使用したいと思います。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileInputStream; // For debugging.
import java.io.FileOutputStream; // For debugging.
import java.io.OutputStream; // For debugging.
import java.io.InputStream; // For debugging.
void coder(File exe, File ord, File cod, File msg, File rls, String tcc )
throws ProcessException {
String[] cmd = {
exe.getPath(), // Executable
ord.getPath(), // InputOrder (IN)
cod.getPath(), // ResultsCodedOrder (OUT)
msg.getPath(), // Messages (OUT)
rls.getPath(), // Releases (IN)
tcc = ""
};
Order codeOrder(File taskdir, Order order) throws ProcessException {
String ordername = order.getName();
// Create temp 'input' files.
File orderFile = createTriconOrderFile(taskdir, order);
File releaseFile = createTriconReleaseFile(taskdir, order);
// Define temp 'output' files.
File messageFile = new File(taskdir, ordername + msgExt);
File codedFile = new File(taskdir, ordername + codExt);
// Code order.
coder(exe,
orderFile,
codedFile,
messageFile,
releaseFile,
"USER 'value' INPUT");
return codedOrder;
}
htmltask.java の「値」(サーブレット、つまり req、resp などを含む) を使用し、それらの「値」を TaskCoderImpl.java の入力として使用することは可能ですか?文字列のみが必要なためです...もしそうなら、私は何かが欠けています...私は本当に誰かを混乱させないことを願っています...
更新: task.jsp の追加:
<%getServletContext().getRequestDispatcher("/Task").forward(request, response);%>
web.xmlサーブレット スタイルの追加
<servlet>
<servlet-name>Task</servlet-name>
<servlet-class>pages.html.HtmlTask</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Task</servlet-name>
<url-pattern>/Task</url-pattern>
</servlet-mapping>