メソッドからサーブレットを呼び出すにはどうすればよいですか?
1つのメソッドはボタンで起動され、そのメソッドでサーブレットを起動したいのですが、サーブレットなので難しいですか?? setRc が doGet を呼び出し、それが逆に processRequest を呼び出します。
public class rc extends HttpServlet {
public void setRc(String rc) throws ServletException, IOException {
rc test = new rc();
test.doGet(null, null);
this.rc = rc;
}
public String getRc() {
return rc;
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("FROM doGet");
response.setContentType("text/xml");
//this is where the debugger quits...
PrintWriterout = response.getWriter();
processRequest(request, response);
setRc(rc);
}
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
name = request.getParameter("rc");
IP = request.getRemoteAddr();
FileWriter fstream = new FileWriter("C:\\commands\\IPLog\\IP.txt");
BufferedWriter txt = new BufferedWriter(fstream);
txt.write(IP);
txt.close();
Process p = Runtime.getRuntime().exec("c:\\commands\\psexec \\\\" + IP + " -s -i C:\\Windows\\System32\\mstsc.exe /v:" + name);
}
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index</title>
</head>
<body>
<jsp:useBean id="info" scope="session" class="org.mypackage.WebTools.info" />
<jsp:setProperty name="info" property="info" />
<jsp:useBean id="hinv" scope="session" class="org.mypackage.WebTools.hinv" />
<jsp:setProperty name="hinv" property="hinv" />
<jsp:useBean id="rc" scope="session" class="org.mypackage.WebTools.rc" />
<jsp:setProperty name="rc" property="rc" />
<jsp:useBean id="remx" scope="session" class="org.mypackage.WebTools.remx" />
<jsp:setProperty name="remx" property="remx" />
<jsp:useBean id="SOne" scope="session" class="org.mypackage.WebTools.SOne" />
<jsp:setProperty name="SOne" property="SOne" />
<b><font color="blue">Please Enter your Full Name here:</font></b><br>
<form name="frm" method="get" action="rc.java">
<table border = "0">
<tr align="left" valign="top">
<td>First Name:</td>
<td><input type="text" name ="name" /></td>
</tr>
<tr align="left" valign="top">
<td></td>
<td><input type="submit" value="submit"/></td>
</tr>
</table>
</form>
<%-- --%>
<table border="1">
<tbody>
<tr>
<td><a href="http://intranet/SITES/UBOX/SUPPORTUNITS/ITG/Pages/Default.aspx?cm_re_o=JPRr%20ZBFwCjCaB5%20WzM%20C%20mA55Byf%20JEbflCjCGa7"><img src="UBLogo.jpg" class ="ublogo" alt="UBLogo"/></a></td>
<td><strong>RDWeb</strong><a href="https://mpsc-dcs-util1/RDWeb/Pages/en-US/Desktops.aspx"><img src="RD.png" class ="rd" alt="UBLogo"/></a></td>
</tbody>
</table>
<table border="1">
<thead>
<tr><th colspan="2">Welcome to Web Tools</th><br>
<th colspan="2">${UserDetails.displayName0}
<br>${UserDetails.Full_User_Name0}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<form name="info" action="index.jsp">
Enter the UB ID, User Name or Computer Name:</td>
<td><input type="text" name="info" />
<input type="submit" value="OK" />
</form>
</td>
<td><strong>Contact Details: </strong></td>
<td><strong>Email: </strong><a href="mailto:${UserDetails.mail0}">${UserDetails.mail0}</a>
<br><strong>IM: </strong><a href="im:<sip:${UserDetails.givenName0}.${UserDetails.sn0}@uboc.com>">${UserDetails.givenName0} ${UserDetails.sn0}</a>
<br><strong>phone:</strong>${UserDetails.telephoneNumber0}
<br><span style="font-size:smaller; font-style:italic;">
<em>last login: ${UserDetails.Login_Date}</em></span></td>
</tr>
<tr>
<td><strong>AD Site</strong></td>
<td><strong>${UserDetails.AD_Site}</strong></td>
<td><strong>Computer</strong></td>
<td><strong>PC: ${UserDetails.Computer_Name}</strong>
<br><strong>OS: ${UserDetails.Network_Operating_System0}</strong>
<br><strong>IP: ${UserDetails.IP_Address}</strong></td>
</tr>
<tr>
<td>
<form name="hinv" action="index.jsp" />
Hardware Inventory:<input type="submit" value="${UserDetails.Computer_Name}" onsubmit=jsp:setProperty name="hinv"/>
</form>
</td>
<td>
<form name="rc" action="index.jsp" />
Remote Control:<input type="submit" value="${UserDetails.Computer_Name}" onsubmit=jsp:setProperty name="rc"/>
</form>
</td>
<td>
<form name="remx" action="index.jsp" />
RemX_OKillX.exe:<input type="submit" value="${UserDetails.Computer_Name}" onsubmit=jsp:setProperty name="remx"/>
</form>
</td>
<td>
<form name="SOne" action="index.jsp" />
5685-SourceOne.exe:<input type="submit" value="${UserDetails.Computer_Name}" onsubmit=jsp:setProperty name="SOne"/>
</form>
</td>
</tr>
</tbody>
</table>
<br>
<table border="1">
<tbody>
<tr>
<c:forEach var="columnName" items="${result.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<!-- column data -->
<c:forEach var="row" items="${result.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>